Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iH5xf-0000va-Pg for pgsql-hackers@arkaria.postgresql.org; Sun, 06 Oct 2019 12:48:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iH5xc-0007MZ-Vr for pgsql-hackers@arkaria.postgresql.org; Sun, 06 Oct 2019 12:48:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iH5xc-0007MM-NG for pgsql-hackers@lists.postgresql.org; Sun, 06 Oct 2019 12:48:28 +0000 Received: from ssl.nataraj.su ([195.54.209.170]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iH5xV-0000bQ-Go for pgsql-hackers@lists.postgresql.org; Sun, 06 Oct 2019 12:48:28 +0000 Received: from x200m.localnet (unknown [91.203.188.92]) by ssl.nataraj.su (Postfix) with ESMTPSA id 657AD511E033; Sun, 6 Oct 2019 15:47:49 +0300 (MSK) From: Nikolay Shaplov To: Tomas Vondra , Nikolay Shaplov , PostgreSQL Hackers , Dent John , "Iwata, Aya" , Alvaro Herrera , Dmitry Dolgov <9erthalion6@gmail.com>, Thomas Munro , Michael Paquier 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> User-Agent: KMail/5.2.3 (Linux/4.9.0-8-amd64; KDE/5.28.0; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart5216643.HbsEMFMWDC"; micalg="pgp-sha256"; protocol="application/pgp-signature" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --nextPart5216643.HbsEMFMWDC Content-Type: multipart/mixed; boundary="nextPart1707139.JZaydOS6Nu" Content-Transfer-Encoding: 7Bit This is a multi-part message in MIME format. --nextPart1707139.JZaydOS6Nu Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" 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) --nextPart1707139.JZaydOS6Nu Content-Disposition: attachment; filename="use-empty-structure-for-partitioned-options_v1.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="utf-8"; name="use-empty-structure-for-partitioned-options_v1.diff" 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! */ --nextPart1707139.JZaydOS6Nu-- --nextPart5216643.HbsEMFMWDC Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part. Content-Transfer-Encoding: 7Bit -----BEGIN PGP SIGNATURE----- iQEzBAABCAAdFiEEJQDMAFm5foZxo7fMpzXcejAr4fgFAl2Z4nIACgkQpzXcejAr 4fiwSAgAgZpmbdAv8PrDvWj5N6yxk/9YKoCA7Uch9aDzZw3OJW0ui/lGNensK3Yq LHc/themwrwW80xROA4DJ+SsyL6VAZjrmQAm8HL3pLjSXMfvUrkk+gHd9HQiWYf7 RPxTOmKZFPGCTSjyBAqpWo4gWS+Q/28l9+hzvoc6Y1BXxj2vKCeFLPVswI4Jat79 i549ljT0CZzLVV4cgpL19u8zoXpaINqzb6EDfyjetMSJr2p8udSdDhT+gzfLVJG0 PRp/NRJ/14Z/r8AzFSK5n7J0Eu16KFRYs8vHDHwjA4pJTUVjPQe+Nr+wIIJG7a75 WI9GOLl4T1maWhiYwLicNUdXNUcfig== =uAN7 -----END PGP SIGNATURE----- --nextPart5216643.HbsEMFMWDC--