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)
diff --git a/src/backend/access/common/reloptions.c b/src/backend/access/common/reloptions.c index 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.c index 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.h index 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.h index 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
Description: This is a digitally signed message part.