From: Nikolay Shaplov <dhyan@nataraj.su>
To: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Nikolay Shaplov <dhyan@nataraj.su>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
To: Dent John <denty@qqdd.eu>
To: Iwata, Aya <iwata.aya@jp.fujitsu.com>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
To: Dmitry Dolgov <9erthalion6@gmail.com>
To: Thomas Munro <thomas.munro@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Subject: [PATCH] use separate PartitionedRelOptions structure to store partitioned table options
Date: Sun, 06 Oct 2019 15:47:46 +0300
Message-ID: <1627387.Qykg9O6zpu@x200m> (raw)
Hi!
This message is follow up to the "Get rid of the StdRdOptions" patch thread:
https://www.postgresql.org/message-id/2620882.s52SJui4ql@x200m
I've split patch into even smaller parts and commitfest want each patch in
separate thread. So it is new thread.
The idea of this patch is following: If you read the code, partitioned tables
do not have any options (you will not find RELOPT_KIND_PARTITIONED in
boolRelOpts, intRelOpts, realRelOpts, stringRelOpts and enumRelOpts in
reloption.c), but it uses StdRdOptions to store them (these no options).
If partitioned table is to have it's own option set (even if it is empty now)
it would be better to save it into separate structure, like it is done for
Views, not adding them to StdRdOptions, like current code hints to do.
So in this patch I am creating a structure that would store partitioned table
options (it is empty for now as there are no options for this relation kind),
and all other code that would use this structure as soon as the first option
comes.
I think it is bad idea to suggest option adder to ad it to StdRdOption, we
already have a big mess there. Better if he add it to an new empty structure.
--
Software Developer: https://www.upwork.com/freelancers/~014a87e140ff02c0da
Body-oriented Therapist: https://vk.com/nataraj_rebalancing (Russian)
Attachments:use-empty-structure-for-partitioned-options_v1.diff (text/x-patch, 4.2K) downloaddiff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.cindex b5072c0..f219ad3 100644--- a/src/backend/access/common/reloptions.c+++ b/src/backend/access/common/reloptions.c@@ -1099,9 +1099,11 @@ extractRelOptions(HeapTuple tuple, TupleDesc tupdesc,
case RELKIND_RELATION:
case RELKIND_TOASTVALUE:
case RELKIND_MATVIEW:
- case RELKIND_PARTITIONED_TABLE:
options = heap_reloptions(classForm->relkind, datum, false);
break;
+ case RELKIND_PARTITIONED_TABLE:+ options = partitioned_reloptions(datum, false);+ break;
case RELKIND_VIEW:
options = view_reloptions(datum, false);
break;
@@ -1538,6 +1540,25 @@ default_reloptions(Datum reloptions, bool validate, relopt_kind kind)
}
/*
+ * Option parser for partitioned relations+ */+bytea *+partitioned_reloptions(Datum reloptions, bool validate)+{+ int numoptions;++ /*+ * Since there is no options for patitioned table for now, we just do+ * validation to report incorrect option error and leave.+ */++ if (validate)+ parseRelOptions(reloptions, validate, RELOPT_KIND_PARTITIONED,+ &numoptions);+ return NULL;+}++/*
* Option parser for views
*/
bytea *
@@ -1593,9 +1614,6 @@ heap_reloptions(char relkind, Datum reloptions, bool validate)
case RELKIND_RELATION:
case RELKIND_MATVIEW:
return default_reloptions(reloptions, validate, RELOPT_KIND_HEAP);
- case RELKIND_PARTITIONED_TABLE:- return default_reloptions(reloptions, validate,- RELOPT_KIND_PARTITIONED);
default:
/* other relkinds are not supported */
return NULL;
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.cindex 05593f3..db27f30 100644--- a/src/backend/commands/tablecmds.c+++ b/src/backend/commands/tablecmds.c@@ -720,10 +720,17 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
reloptions = transformRelOptions((Datum) 0, stmt->options, NULL, validnsps,
true, false);
- if (relkind == RELKIND_VIEW)- (void) view_reloptions(reloptions, true);- else- (void) heap_reloptions(relkind, reloptions, true);+ switch ((int)relkind)+ {+ case RELKIND_VIEW:+ (void) view_reloptions(reloptions, true);+ break;+ case RELKIND_PARTITIONED_TABLE:+ (void) partitioned_reloptions(reloptions, true);+ break;+ default:+ (void) heap_reloptions(relkind, reloptions, true);+ }
if (stmt->ofTypename)
{
@@ -12158,9 +12165,11 @@ ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation,
case RELKIND_RELATION:
case RELKIND_TOASTVALUE:
case RELKIND_MATVIEW:
- case RELKIND_PARTITIONED_TABLE:
(void) heap_reloptions(rel->rd_rel->relkind, newOptions, true);
break;
+ case RELKIND_PARTITIONED_TABLE:+ (void) partitioned_reloptions(newOptions, true);+ break;
case RELKIND_VIEW:
(void) view_reloptions(newOptions, true);
break;
diff --git a/src/include/access/reloptions.h b/src/include/access/reloptions.hindex 6bde209..0ad5c74 100644--- a/src/include/access/reloptions.h+++ b/src/include/access/reloptions.h@@ -301,6 +301,7 @@ extern bytea *default_reloptions(Datum reloptions, bool validate,
relopt_kind kind);
extern bytea *heap_reloptions(char relkind, Datum reloptions, bool validate);
extern bytea *view_reloptions(Datum reloptions, bool validate);
+extern bytea *partitioned_reloptions(Datum reloptions, bool validate);
extern bytea *index_reloptions(amoptions_function amoptions, Datum reloptions,
bool validate);
extern bytea *attribute_reloptions(Datum reloptions, bool validate);
diff --git a/src/include/utils/rel.h b/src/include/utils/rel.hindex a5cf804..ba8aa51 100644--- a/src/include/utils/rel.h+++ b/src/include/utils/rel.h@@ -278,6 +278,16 @@ typedef struct StdRdOptions
#define HEAP_DEFAULT_FILLFACTOR 100
/*
+ * PartitionedRelOptions+ * Binary representation of relation options for Partitioned relations.+ */+typedef struct PartitionedRelOptions+{+ int32 vl_len_; /* varlena header (do not touch directly!) */+ /* No options defined yet */+} PartitionedRelOptions;++/*
* RelationGetToastTupleTarget
* Returns the relation's toast_tuple_target. Note multiple eval of argument!
*/
signature.asc (application/pgp-signature, 487B) download
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: dhyan@nataraj.su, tomas.vondra@2ndquadrant.com, denty@qqdd.eu, iwata.aya@jp.fujitsu.com, alvherre@2ndquadrant.com, 9erthalion6@gmail.com, thomas.munro@gmail.com, michael@paquier.xyz
Subject: Re: [PATCH] use separate PartitionedRelOptions structure to store partitioned table options
In-Reply-To: <1627387.Qykg9O6zpu@x200m>
References: <1627387.Qykg9O6zpu@x200m>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox