pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dmitry Koval <d.koval@postgrespro.ru>
To: Alexander Lakhin <exclusion@gmail.com>
To: Alexander Korotkov <aekorotkov@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Cc: Richard Guo <guofenglinux@gmail.com>
Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
Date: Wed, 10 Apr 2024 20:22:35 +0300
Message-ID: <86bfd241-a58c-479a-9a72-2c67a02becf8@postgrespro.ru> (raw)
In-Reply-To: <dbc8b96c-3cf0-d1ee-860d-0e491da20485@gmail.com>
References: <c73a1746-0cd0-6bdd-6b23-3ae0b7c0c582@postgrespro.ru>
	<171085858750.2046434.12246066729700037354.pgcf@coridan.postgresql.org>
	<909e16b4-9eda-435c-b033-8294ae4adc05@postgrespro.ru>
	<CAPpHfdsVQwnZPxaQPwcu1g_01F0d-o=ECRcf14X3CmavJB6vSQ@mail.gmail.com>
	<a83d5a56-ff33-47e8-b2d8-7e9a5d59ee1e@postgrespro.ru>
	<CAPpHfdsCCV8DOv0Ovu4dTSnuWXiEz_AjuW-J6TPj++tcfEGvRw@mail.gmail.com>
	<3a4b9c1c-3edf-4e29-9629-b4113aefb0f3@postgrespro.ru>
	<CAPpHfduNYkMVuUSxZjD6u4tZG6aKdhgQcmhr-K9OQfeg56MNww@mail.gmail.com>
	<c3730d78-6081-4c41-9715-d1d192734576@postgrespro.ru>
	<CAPpHfdtj7YsPaASoVPN+N3H4_Ct+kQw8QY1d_9u7FPnbghkicw@mail.gmail.com>
	<CAHewXNkGMPU50QG7V6Q60JGFORfo8LfYO1_GCkCa0VWbmB-fEw@mail.gmail.com>
	<28ed1ee0-749d-9838-955e-abff42fc44be@gmail.com>
	<ce654fca-74cf-44fb-a7e6-d35e3718179c@postgrespro.ru>
	<CAPpHfdtTgSdbzfcEz_mgVxh8VSDP=VfQ6r4T1n9SMT_impbDiA@mail.gmail.com>
	<b56918c2-b099-9875-aa4e-8fd405cdb6ab@gmail.com>
	<dbc8b96c-3cf0-d1ee-860d-0e491da20485@gmail.com>

Hi!

Alexander Korotkov, thanks for the commit of previous fix.
Alexander Lakhin, thanks for the problem you found.

There are two corrections attached to the letter:

1) v1-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch - fix 
for the problem [1].

2) v1-0002-Fixes-for-english-text.patch - fixes for English text 
(comments, error messages etc.).

Links:
[1] 
https://www.postgresql.org/message-id/dbc8b96c-3cf0-d1ee-860d-0e491da20485%40gmail.com

-- 
With best regards,
Dmitry Koval

Postgres Professional: http://postgrespro.com

Attachments: download all (2 files, .tar.gz)

v1-0001-Fix-for-SPLIT-MERGE-partitions-of-temporary-table.patch (text/plain, 10.7K) download From 3c443a57c334c74e9218fd4e2f1ced45e6d4141d Mon Sep 17 00:00:00 2001 From: Koval Dmitry <d.koval@postgrespro.ru> Date: Wed, 10 Apr 2024 18:54:05 +0300 Subject: [PATCH v1 1/2] Fix for SPLIT/MERGE partitions of temporary table --- src/backend/commands/tablecmds.c | 11 ++++--- src/backend/parser/parse_utilcmd.c | 2 +- src/test/regress/expected/partition_merge.out | 32 +++++++++++++++++-- src/test/regress/expected/partition_split.out | 29 +++++++++++++++++ src/test/regress/sql/partition_merge.sql | 24 +++++++++++++- src/test/regress/sql/partition_split.sql | 23 +++++++++++++ 6 files changed, 113 insertions(+), 8 deletions(-) diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 8a98a0af48..3da9f6389d 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -21145,17 +21145,19 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar * createPartitionTable: create table for a new partition with given name * (newPartName) like table (modelRelName) * - * Emulates command: CREATE TABLE <newPartName> (LIKE <modelRelName> + * Emulates command: CREATE [TEMP] TABLE <newPartName> (LIKE <modelRelName> * INCLUDING ALL EXCLUDING INDEXES EXCLUDING IDENTITY) */ static void -createPartitionTable(RangeVar *newPartName, RangeVar *modelRelName, +createPartitionTable(Relation rel, RangeVar *newPartName, RangeVar *modelRelName, AlterTableUtilityContext *context) { CreateStmt *createStmt; TableLikeClause *tlc; PlannedStmt *wrapper; + newPartName->relpersistence = rel->rd_rel->relpersistence; + createStmt = makeNode(CreateStmt); createStmt->relation = newPartName; createStmt->tableElts = NIL; @@ -21291,7 +21293,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel, SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr); Relation newPartRel; - createPartitionTable(sps->name, parentName, context); + createPartitionTable(rel, sps->name, parentName, context); /* Open the new partition and acquire exclusive lock on it. */ newPartRel = table_openrv(sps->name, AccessExclusiveLock); @@ -21491,7 +21493,8 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel, mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)), tmpRelName, -1); } - createPartitionTable(mergePartName, + createPartitionTable(rel, + mergePartName, makeRangeVar(get_namespace_name(RelationGetNamespace(rel)), RelationGetRelationName(rel), -1), context); diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index ceba069905..ef1a2a97c0 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -3430,7 +3430,7 @@ checkPartition(Relation rel, Oid partRelOid) if (partRel->rd_rel->relkind != RELKIND_RELATION) ereport(ERROR, (errcode(ERRCODE_WRONG_OBJECT_TYPE), - errmsg("\"%s\" is not a table", + errmsg("\"%s\" is not a ordinary table", RelationGetRelationName(partRel)))); if (!partRel->rd_rel->relispartition) diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out index 60eacf6bf3..c69a717aaa 100644 --- a/src/test/regress/expected/partition_merge.out +++ b/src/test/regress/expected/partition_merge.out @@ -25,9 +25,9 @@ ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_fe ERROR: partition with name "sales_feb2022" already used LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2... ^ --- ERROR: "sales_apr2022" is not a table +-- ERROR: "sales_apr2022" is not a ordinary table ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022; -ERROR: "sales_apr2022" is not a table +ERROR: "sales_apr2022" is not a ordinary table -- ERROR: invalid partitions order, partition "sales_mar2022" can not be merged -- (space between sections sales_jan2022 and sales_mar2022) ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022; @@ -746,4 +746,32 @@ DROP TABLE t3; DROP TABLE t2; DROP TABLE t1; -- +-- Try to MERGE partitions of temporary table. +-- +CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i); +CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1); +CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2); +SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence + FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i + WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass + ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text; + oid | pg_get_expr | relpersistence +--------+----------------------------+---------------- + tp_0_1 | FOR VALUES FROM (0) TO (1) | t + tp_1_2 | FOR VALUES FROM (1) TO (2) | t +(2 rows) + +ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; +-- Partition should be temporary. +SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence + FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i + WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass + ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text; + oid | pg_get_expr | relpersistence +--------+----------------------------+---------------- + tp_0_2 | FOR VALUES FROM (0) TO (2) | t +(1 row) + +DROP TABLE t; +-- DROP SCHEMA partitions_merge_schema; diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out index 26a0d09969..3d22083e41 100644 --- a/src/test/regress/expected/partition_split.out +++ b/src/test/regress/expected/partition_split.out @@ -1427,4 +1427,33 @@ ERROR: relation "t1pa" is not a partition of relation "t2" DROP TABLE t2; DROP TABLE t1; -- +-- Try to SPLIT partition of temporary table. +-- +CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i); +CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2); +SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence + FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i + WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass + ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text; + oid | pg_get_expr | relpersistence +--------+----------------------------+---------------- + tp_0_2 | FOR VALUES FROM (0) TO (2) | t +(1 row) + +ALTER TABLE t SPLIT PARTITION tp_0_2 INTO + (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1), + PARTITION tp_1_2 FOR VALUES FROM (1) TO (2)); +-- Partitions should be temporary. +SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence + FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i + WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass + ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text; + oid | pg_get_expr | relpersistence +--------+----------------------------+---------------- + tp_0_1 | FOR VALUES FROM (0) TO (1) | t + tp_1_2 | FOR VALUES FROM (1) TO (2) | t +(2 rows) + +DROP TABLE t; +-- DROP SCHEMA partition_split_schema; diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql index 9afed70365..cce5ffa29f 100644 --- a/src/test/regress/sql/partition_merge.sql +++ b/src/test/regress/sql/partition_merge.sql @@ -28,7 +28,7 @@ CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; -- ERROR: partition with name "sales_feb2022" already used ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022; --- ERROR: "sales_apr2022" is not a table +-- ERROR: "sales_apr2022" is not a ordinary table ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022; -- ERROR: invalid partitions order, partition "sales_mar2022" can not be merged -- (space between sections sales_jan2022 and sales_mar2022) @@ -444,5 +444,27 @@ DROP TABLE t3; DROP TABLE t2; DROP TABLE t1; +-- +-- Try to MERGE partitions of temporary table. +-- +CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i); +CREATE TEMP TABLE tp_0_1 PARTITION OF t FOR VALUES FROM (0) TO (1); +CREATE TEMP TABLE tp_1_2 PARTITION OF t FOR VALUES FROM (1) TO (2); + +SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence + FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i + WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass + ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text; + +ALTER TABLE t MERGE PARTITIONS (tp_0_1, tp_1_2) INTO tp_0_2; + +-- Partition should be temporary. +SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence + FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i + WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass + ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text; + +DROP TABLE t; + -- DROP SCHEMA partitions_merge_schema; diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql index 625b01ddd1..5dc2fc39cd 100644 --- a/src/test/regress/sql/partition_split.sql +++ b/src/test/regress/sql/partition_split.sql @@ -844,5 +844,28 @@ ALTER TABLE t2 SPLIT PARTITION t1pa INTO DROP TABLE t2; DROP TABLE t1; +-- +-- Try to SPLIT partition of temporary table. +-- +CREATE TEMP TABLE t (i int) PARTITION BY RANGE (i); +CREATE TEMP TABLE tp_0_2 PARTITION OF t FOR VALUES FROM (0) TO (2); + +SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence + FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i + WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass + ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text; + +ALTER TABLE t SPLIT PARTITION tp_0_2 INTO + (PARTITION tp_0_1 FOR VALUES FROM (0) TO (1), + PARTITION tp_1_2 FOR VALUES FROM (1) TO (2)); + +-- Partitions should be temporary. +SELECT c.oid::pg_catalog.regclass, pg_catalog.pg_get_expr(c.relpartbound, c.oid), c.relpersistence + FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i + WHERE c.oid = i.inhrelid AND i.inhparent = 't'::regclass + ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT', c.oid::pg_catalog.regclass::pg_catalog.text; + +DROP TABLE t; + -- DROP SCHEMA partition_split_schema; -- 2.40.1.windows.1
v1-0002-Fixes-for-english-text.patch (text/plain, 41.9K) download From ecbcbf622ae54bfeee7b92759058a117169dca5b Mon Sep 17 00:00:00 2001 From: Koval Dmitry <d.koval@postgrespro.ru> Date: Wed, 10 Apr 2024 19:55:18 +0300 Subject: [PATCH v1 2/2] Fixes for english text --- doc/src/sgml/ddl.sgml | 2 +- doc/src/sgml/ref/alter_table.sgml | 6 +-- src/backend/commands/tablecmds.c | 18 +++---- src/backend/parser/parse_utilcmd.c | 6 +-- src/backend/partitioning/partbounds.c | 28 +++++------ src/test/isolation/specs/partition-merge.spec | 2 +- src/test/regress/expected/partition_merge.out | 14 +++--- src/test/regress/expected/partition_split.out | 50 +++++++++---------- src/test/regress/sql/partition_merge.sql | 12 ++--- src/test/regress/sql/partition_split.sql | 42 ++++++++-------- 10 files changed, 90 insertions(+), 90 deletions(-) diff --git a/doc/src/sgml/ddl.sgml b/doc/src/sgml/ddl.sgml index 00f44f56fa..026bfff70f 100644 --- a/doc/src/sgml/ddl.sgml +++ b/doc/src/sgml/ddl.sgml @@ -4387,7 +4387,7 @@ ALTER INDEX measurement_city_id_logdate_key a single partition using the <link linkend="sql-altertable-merge-partitions"><command>ALTER TABLE ... MERGE PARTITIONS</command></link>. This feature simplifies the management of partitioned tables by allowing - administrators to combine partitions that are no longer needed as + users to combine partitions that are no longer needed as separate entities. It's important to note that this operation is not supported for hash-partitioned tables and acquires an <literal>ACCESS EXCLUSIVE</literal> lock, which could impact high-load diff --git a/doc/src/sgml/ref/alter_table.sgml b/doc/src/sgml/ref/alter_table.sgml index 8f5bf185dd..fe36ff82e5 100644 --- a/doc/src/sgml/ref/alter_table.sgml +++ b/doc/src/sgml/ref/alter_table.sgml @@ -1175,7 +1175,7 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM <itemizedlist> <listitem> <para> - For range-partitioned tables is necessary that the ranges + For range-partitioned tables it is necessary that the ranges of the partitions <replaceable class="parameter">partition_name1</replaceable>, <replaceable class="parameter">partition_name2</replaceable> [, ...] can be merged into one range without spaces and overlaps (otherwise an error @@ -1185,10 +1185,10 @@ WITH ( MODULUS <replaceable class="parameter">numeric_literal</replaceable>, REM </listitem> <listitem> <para> - For list-partitioned tables the values lists of all partitions + For list-partitioned tables the value lists of all partitions <replaceable class="parameter">partition_name1</replaceable>, <replaceable class="parameter">partition_name2</replaceable> [, ...] are - combined and form a list of values of partition + combined and form the list of values of partition <replaceable class="parameter">partition_name</replaceable>. </para> </listitem> diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index 3da9f6389d..c44d9c1db6 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -20888,7 +20888,7 @@ GetAttributeStorage(Oid atttypid, const char *storagemode) } /* - * Struct with context of new partition for insert rows from splited partition + * Struct with context of new partition for inserting rows from split partition */ typedef struct SplitPartitionContext { @@ -20945,7 +20945,7 @@ deleteSplitPartitionContext(SplitPartitionContext *pc, int ti_options) * * New partitions description: * partlist: list of pointers to SinglePartitionSpec structures. - * newPartRels: list of Relation's. + * newPartRels: list of Relations. * defaultPartOid: oid of DEFAULT partition, for table rel. */ static void @@ -21030,7 +21030,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar /* * Map computing for moving attributes of split partition to new partition - * (for first new partition but other new partitions can use the same + * (for first new partition, but other new partitions can use the same * map). */ pc = (SplitPartitionContext *) lfirst(list_head(partContexts)); @@ -21085,7 +21085,7 @@ moveSplitTableRows(Relation rel, Relation splitRel, List *partlist, List *newPar if (tuple_map) { - /* Need to use map for copy attributes. */ + /* Need to use map to copy attributes. */ insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, pc->dstslot); } else @@ -21245,7 +21245,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel, RangeVarGetAndCheckCreationNamespace(sps->name, NoLock, NULL); /* - * This would fail later on anyway, if the relation already exists. + * This would fail later on anyway if the relation already exists. * But by catching it here we can emit a nicer error message. */ existing_relid = get_relname_relid(relname, namespaceId); @@ -21312,7 +21312,7 @@ ATExecSplitPartition(List **wqueue, AlteredTableInfo *tab, Relation rel, SinglePartitionSpec *sps = (SinglePartitionSpec *) lfirst(listptr); Relation newPartRel = (Relation) lfirst(listptr2); - /* wqueue = NULL: verification for each cloned constraint is not need. */ + /* wqueue = NULL: verification for each cloned constraint is not needed. */ attachPartitionTable(NULL, rel, newPartRel, sps->bound); /* Keep the lock until commit. */ table_close(newPartRel, NoLock); @@ -21386,7 +21386,7 @@ moveMergedTablesRows(Relation rel, List *mergingPartitionsList, if (tuple_map) { - /* Need to use map for copy attributes. */ + /* Need to use map to copy attributes. */ insertslot = execute_attr_map_slot(tuple_map->attrMap, srcslot, dstslot); } else @@ -21488,7 +21488,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel, /* Create table for new partition, use partitioned table as model. */ if (isSameName) { - /* Create partition table with generated temparary name. */ + /* Create partition table with generated temporary name. */ sprintf(tmpRelName, "merge-%u-%X-tmp", RelationGetRelid(rel), MyProcPid); mergePartName = makeRangeVar(get_namespace_name(RelationGetNamespace(rel)), tmpRelName, -1); @@ -21512,7 +21512,7 @@ ATExecMergePartitions(List **wqueue, AlteredTableInfo *tab, Relation rel, /* * Attach a new partition to the partitioned table. wqueue = NULL: - * verification for each cloned constraint is not need. + * verification for each cloned constraint is not needed. */ attachPartitionTable(NULL, rel, newPartRel, cmd->bound); diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index ef1a2a97c0..82b6ba7fc6 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -3492,7 +3492,7 @@ transformPartitionCmdForSplit(CreateStmtContext *cxt, PartitionCmd *partcmd) * transformPartitionCmdForMerge * Analyze the ALTER TABLLE ... MERGE PARTITIONS command * - * Does simple checks for merged partitions. Calculates bound of result + * Does simple checks for merged partitions. Calculates bound of resulting * partition. */ static void @@ -3537,7 +3537,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd) if (equal(name, name2)) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_TABLE), - errmsg("partition with name \"%s\" already used", name->relname)), + errmsg("partition with name \"%s\" is already used", name->relname)), parser_errposition(cxt->pstate, name2->location)); } @@ -3551,7 +3551,7 @@ transformPartitionCmdForMerge(CreateStmtContext *cxt, PartitionCmd *partcmd) partOids = lappend_oid(partOids, partOid); } - /* Allocate bound of result partition. */ + /* Allocate bound of resulting partition. */ Assert(partcmd->bound == NULL); partcmd->bound = makeNode(PartitionBoundSpec); diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioning/partbounds.c index c0c49b0a0b..1c8396e83c 100644 --- a/src/backend/partitioning/partbounds.c +++ b/src/backend/partitioning/partbounds.c @@ -3214,7 +3214,7 @@ check_new_partition_bound(char *relname, Relation parent, PartitionRangeDatum *datum; /* - * Point to problematic key in the lower datums list; + * Point to problematic key in the list of lower datums; * if we have equality, point to the first one. */ datum = cmpval == 0 ? linitial(spec->lowerdatums) : @@ -4986,10 +4986,10 @@ satisfies_hash_partition(PG_FUNCTION_ARGS) * This is a helper function for check_partitions_for_split() and * calculate_partition_bound_for_merge(). * This function compares upper bound of first_bound and lower bound of - * second_bound. These bounds should be equal except case + * second_bound. These bounds should be equal except when * "defaultPart == true" (this means that one of split partitions is DEFAULT). * In this case upper bound of first_bound can be less than lower bound of - * second_bound because space between of these bounds will be included in + * second_bound because space between these bounds will be included in * DEFAULT partition. * * parent: partitioned table @@ -4998,7 +4998,7 @@ satisfies_hash_partition(PG_FUNCTION_ARGS) * second_name: name of second partition * second_bound: bound of second partition * defaultPart: true if one of split partitions is DEFAULT - * pstate: pointer to ParseState struct for determine error position + * pstate: pointer to ParseState struct for determining error position */ static void check_two_partitions_bounds_range(Relation parent, @@ -5020,7 +5020,7 @@ check_two_partitions_bounds_range(Relation parent, second_lower = make_one_partition_rbound(key, -1, second_bound->lowerdatums, true); /* - * lower1=false (the second to last argument) for correct comparison lower + * lower1=false (the second to last argument) for correct comparison of lower * and upper bounds. */ cmpval = partition_rbound_cmp(key->partnatts, @@ -5140,7 +5140,7 @@ get_partition_bound_spec(Oid partOid, RangeVar *name) * * (function for BY RANGE partitioning) * - * Checks that bounds of new partition "spec" is inside bounds of split + * Checks that bounds of new partition "spec" are inside bounds of split * partition (with Oid splitPartOid). If first=true (this means that "spec" is * the first of new partitions) then lower bound of "spec" should be equal (or * greater than or equal in case defaultPart=true) to lower bound of split @@ -5274,7 +5274,7 @@ check_partition_bounds_for_split_range(Relation parent, * * (function for BY LIST partitioning) * - * Checks that bounds of new partition is inside bounds of split partition + * Checks that bounds of new partition are inside bounds of split partition * (with Oid splitPartOid). * * parent: partitioned table @@ -5445,8 +5445,8 @@ check_parent_values_in_new_partitions(Relation parent, Assert(key->strategy == PARTITION_STRATEGY_LIST); /* - * Special processing for NULL value. Search NULL-value if it contains - * split partition (partOid). + * Special processing for NULL value. Search NULL value if the split + * partition (partOid) contains it. */ if (partition_bound_accepts_nulls(boundinfo) && partdesc->oids[boundinfo->null_index] == partOid) @@ -5461,7 +5461,7 @@ check_parent_values_in_new_partitions(Relation parent, /* * Search all values of split partition with partOid in PartitionDesc of - * partitionde table. + * partitioned table. */ for (i = 0; i < boundinfo->ndatums; i++) { @@ -5498,7 +5498,7 @@ check_parent_values_in_new_partitions(Relation parent, ereport(ERROR, (errcode(ERRCODE_INVALID_OBJECT_DEFINITION), - errmsg("new partitions not have value %s but split partition has", + errmsg("new partitions do not have value %s but split partition has", searchNull ? "NULL" : get_list_partvalue_string(notFoundVal)))); } } @@ -5714,7 +5714,7 @@ check_partitions_for_split(Relation parent, if (equal(sps->name, sps2->name)) ereport(ERROR, (errcode(ERRCODE_DUPLICATE_TABLE), - errmsg("name \"%s\" already used", sps2->name->relname)), + errmsg("name \"%s\" is already used", sps2->name->relname)), parser_errposition(pstate, sps2->name->location)); } } @@ -5805,14 +5805,14 @@ calculate_partition_bound_for_merge(Relation parent, } /* - * Lower bound of first partition is a lower bound of merged + * Lower bound of first partition is the lower bound of merged * partition. */ spec->lowerdatums = ((PartitionBoundSpec *) list_nth(bounds, lower_bounds[0]->index))->lowerdatums; /* - * Upper bound of last partition is a upper bound of merged + * Upper bound of last partition is the upper bound of merged * partition. */ spec->upperdatums = diff --git a/src/test/isolation/specs/partition-merge.spec b/src/test/isolation/specs/partition-merge.spec index ec48732c58..dc2b9d3445 100644 --- a/src/test/isolation/specs/partition-merge.spec +++ b/src/test/isolation/specs/partition-merge.spec @@ -38,7 +38,7 @@ step s2s { SELECT * FROM tpart; } # s2 inserts row into table. s1 starts MERGE PARTITIONS then -# s2 trying to update inserted row and waits until s1 finished +# s2 is trying to update inserted row and waits until s1 finishes # MERGE operation. permutation s2b s2i s2c s1b s1merg s2b s2u s1c s2c s2s diff --git a/src/test/regress/expected/partition_merge.out b/src/test/regress/expected/partition_merge.out index c69a717aaa..6e25365124 100644 --- a/src/test/regress/expected/partition_merge.out +++ b/src/test/regress/expected/partition_merge.out @@ -20,19 +20,19 @@ CREATE TABLE sales_apr_1 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-01 CREATE TABLE sales_apr_2 PARTITION OF sales_apr2022 FOR VALUES FROM ('2022-04-15') TO ('2022-05-01'); ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'); CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; --- ERROR: partition with name "sales_feb2022" already used +-- ERROR: partition with name "sales_feb2022" is already used ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022; -ERROR: partition with name "sales_feb2022" already used +ERROR: partition with name "sales_feb2022" is already used LINE 1: ...e MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2... ^ -- ERROR: "sales_apr2022" is not a ordinary table ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022; ERROR: "sales_apr2022" is not a ordinary table --- ERROR: invalid partitions order, partition "sales_mar2022" can not be merged +-- ERROR: lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022" -- (space between sections sales_jan2022 and sales_mar2022) ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022; ERROR: lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022" --- ERROR: invalid partitions order, partition "sales_jan2022" can not be merged +-- ERROR: lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021" -- (space between sections sales_dec2021 and sales_jan2022) ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022; ERROR: lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021" @@ -52,7 +52,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge DROP TABLE sales_range; -- --- Add rows into partitioned table then merge partitions +-- Add rows into partitioned table, then merge partitions -- CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date); CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01'); @@ -162,7 +162,7 @@ SELECT * FROM sales_others; 14 | Smith | 510 | 05-04-2022 (1 row) --- Use indexscan for test indexes +-- Use indexscan for testing indexes SET enable_seqscan = OFF; SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01'; salesman_id | salesman_name | sales_amount | sales_date @@ -704,7 +704,7 @@ SELECT * FROM sales_all; 13 | Gandi | Warsaw | 150 | 03-08-2022 (10 rows) --- Use indexscan for test indexes after merge partitions +-- Use indexscan for testing indexes after merging partitions SET enable_seqscan = OFF; SELECT * FROM sales_all WHERE sales_state = 'Warsaw'; salesman_id | salesman_name | sales_state | sales_amount | sales_date diff --git a/src/test/regress/expected/partition_split.out b/src/test/regress/expected/partition_split.out index 3d22083e41..87417b7796 100644 --- a/src/test/regress/expected/partition_split.out +++ b/src/test/regress/expected/partition_split.out @@ -43,7 +43,7 @@ ERROR: empty range bound specified for partition "sales_mar2022" LINE 3: PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO... ^ DETAIL: Specified lower bound ('03-01-2022') is greater than or equal to upper bound ('02-01-2022'). ---ERROR: list of split partitions should contains at least two items +--ERROR: list of split partitions should contain at least two items ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01')); ERROR: list of new partitions should contain at least two items @@ -55,21 +55,21 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO ERROR: lower bound of partition "sales_feb2022" is less than lower bound of split partition LINE 2: (PARTITION sales_feb2022 FOR VALUES FROM ('2022-01-01') TO... ^ --- ERROR: name "sales_feb_mar_apr2022" already used +-- ERROR: name "sales_feb_mar_apr2022" is already used -- (We can create partition with the same name as split partition, but can't create two partitions with the same name) ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); -ERROR: name "sales_feb_mar_apr2022" already used +ERROR: name "sales_feb_mar_apr2022" is already used LINE 3: PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03... ^ --- ERROR: name "sales_feb2022" already used +-- ERROR: name "sales_feb2022" is already used ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); -ERROR: name "sales_feb2022" already used +ERROR: name "sales_feb2022" is already used LINE 3: PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO... ^ -- ERROR: "sales_feb_mar_apr2022" is not a partitioned table @@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO ERROR: upper bound of partition "sales_apr2022" is greater than upper bound of split partition LINE 4: ... sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-0... ^ --- ERROR: lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition +-- ERROR: lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022" ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'), @@ -96,7 +96,7 @@ LINE 3: PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO... ^ -- Tests for spaces between partitions, them should be executed without DEFAULT partition ALTER TABLE sales_range DETACH PARTITION sales_others; --- ERROR: lower bound of partition "sales_feb2022" is not equals to lower bound of split partition +-- ERROR: lower bound of partition "sales_feb2022" is not equal to lower bound of split partition ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), @@ -191,7 +191,7 @@ SELECT * FROM sales_others; DROP TABLE sales_range CASCADE; -- --- Add split partition then add rows into partitioned table +-- Add split partition, then add rows into partitioned table -- CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date); CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01'); @@ -394,7 +394,7 @@ LINE 1: SELECT * FROM sales_jan_feb2022; ^ DROP TABLE sales_date CASCADE; -- --- Test: split DEFAULT partition; using a index on partition key; check index after split +-- Test: split DEFAULT partition; use an index on partition key; check index after split -- CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date); CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01'); @@ -441,7 +441,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'), PARTITION sales_others DEFAULT); --- Use indexscan for test indexes +-- Use indexscan for testing indexes SET enable_indexscan = ON; SET enable_seqscan = OFF; SELECT * FROM sales_feb2022 where sales_date > '2022-01-01'; @@ -503,7 +503,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part DROP TABLE sales_range CASCADE; -- --- Test: some cases for split DEFAULT partition (different bounds) +-- Test: some cases for splitting DEFAULT partition (different bounds) -- CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date); CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; @@ -537,7 +537,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO ERROR: lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022" LINE 3: PARTITION sales_error FOR VALUES FROM (20211210) TO (2021... ^ --- sales_error intersects with sales_dec2022 (exact the same bounds) +-- sales_error intersects with sales_dec2022 (exactly the same bounds) -- ERROR: lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022" ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101), @@ -555,7 +555,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO ERROR: any partition in the list should be DEFAULT because split partition is DEFAULT LINE 2: (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20... ^ --- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022 +-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101), PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120), @@ -564,7 +564,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO DROP TABLE sales_range; CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date); CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; --- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022 +-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101), PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201), @@ -629,7 +629,7 @@ INSERT INTO sales_range VALUES (1, 10, '2022-03-11'); DROP TABLE sales_range CASCADE; DROP TABLE salesmans CASCADE; -- --- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table +-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table -- CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id); CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE); @@ -770,11 +770,11 @@ DROP TABLE salesmans CASCADE; DROP FUNCTION after_insert_row_trigger(); -- -- Test: split partition witch identity column --- If split partition column is identity-column, columns of new partitions are identity-columns too. +-- If split partition column is identity column, columns of new partitions are identity columns too. -- CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id); CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2); --- Create new partition with identity-column: +-- Create new partition with identity column: CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30)); ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5); INSERT INTO salesmans (salesman_name) VALUES ('Poirot'); @@ -793,7 +793,7 @@ SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND salesman_name | | (2 rows) --- Split partition has identity-column: +-- Split partition has identity column: SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid; attname | attidentity | attgenerated ---------------+-------------+-------------- @@ -1063,8 +1063,8 @@ LINE 2: ...s_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid', NULL), DROP TABLE sales_list; -- -- Test: two specific errors for BY LIST partitioning: --- * new partitions not has NULL value that split partition has. --- * new partitions not has a value that split partition has. +-- * new partitions do not have NULL value, which split partition has. +-- * new partitions do not have a value that split partition has. -- CREATE TABLE sales_list (salesman_id INT, @@ -1075,18 +1075,18 @@ CREATE TABLE sales_list PARTITION BY LIST (sales_state); CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo'); CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL); --- ERROR: new partitions not have value NULL but split partition has +-- ERROR: new partitions do not have value NULL but split partition has ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'), PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv')); -ERROR: new partitions not have value NULL but split partition has --- ERROR: new partitions not have value 'Kyiv' but split partition has +ERROR: new partitions do not have value NULL but split partition has +-- ERROR: new partitions do not have value 'Kyiv' but split partition has ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'), PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', NULL)); -ERROR: new partitions not have value 'Kyiv' but split partition has +ERROR: new partitions do not have value 'Kyiv' but split partition has DROP TABLE sales_list; -- -- Test: BY LIST partitioning, SPLIT PARTITION with data @@ -1174,7 +1174,7 @@ SELECT * FROM sales_central; 13 | Gandi | Warsaw | 150 | 03-08-2022 (4 rows) --- Use indexscan for test indexes after split partition +-- Use indexscan for testing indexes after splitting partition SET enable_indexscan = ON; SET enable_seqscan = OFF; SELECT * FROM sales_central WHERE sales_state = 'Warsaw'; diff --git a/src/test/regress/sql/partition_merge.sql b/src/test/regress/sql/partition_merge.sql index cce5ffa29f..c96120a4ad 100644 --- a/src/test/regress/sql/partition_merge.sql +++ b/src/test/regress/sql/partition_merge.sql @@ -26,14 +26,14 @@ ALTER TABLE sales_range ATTACH PARTITION sales_apr2022 FOR VALUES FROM ('2022-04 CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; --- ERROR: partition with name "sales_feb2022" already used +-- ERROR: partition with name "sales_feb2022" is already used ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_feb2022) INTO sales_feb_mar_apr2022; -- ERROR: "sales_apr2022" is not a ordinary table ALTER TABLE sales_range MERGE PARTITIONS (sales_feb2022, sales_mar2022, sales_apr2022) INTO sales_feb_mar_apr2022; --- ERROR: invalid partitions order, partition "sales_mar2022" can not be merged +-- ERROR: lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_jan2022" -- (space between sections sales_jan2022 and sales_mar2022) ALTER TABLE sales_range MERGE PARTITIONS (sales_jan2022, sales_mar2022) INTO sales_jan_mar2022; --- ERROR: invalid partitions order, partition "sales_jan2022" can not be merged +-- ERROR: lower bound of partition "sales_jan2022" conflicts with upper bound of previous partition "sales_dec2021" -- (space between sections sales_dec2021 and sales_jan2022) ALTER TABLE sales_range MERGE PARTITIONS (sales_dec2021, sales_jan2022, sales_feb2022) INTO sales_dec_jan_feb2022; @@ -48,7 +48,7 @@ SELECT c.oid::pg_catalog.regclass, c.relkind, inhdetachpending, pg_catalog.pg_ge DROP TABLE sales_range; -- --- Add rows into partitioned table then merge partitions +-- Add rows into partitioned table, then merge partitions -- CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date); CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01'); @@ -96,7 +96,7 @@ SELECT * FROM sales_jan2022; SELECT * FROM sales_feb_mar_apr2022; SELECT * FROM sales_others; --- Use indexscan for test indexes +-- Use indexscan for testing indexes SET enable_seqscan = OFF; SELECT * FROM sales_feb_mar_apr2022 where sales_date > '2022-01-01'; @@ -415,7 +415,7 @@ SELECT * FROM sales_list; SELECT * FROM sales_nord; SELECT * FROM sales_all; --- Use indexscan for test indexes after merge partitions +-- Use indexscan for testing indexes after merging partitions SET enable_seqscan = OFF; SELECT * FROM sales_all WHERE sales_state = 'Warsaw'; diff --git a/src/test/regress/sql/partition_split.sql b/src/test/regress/sql/partition_split.sql index 5dc2fc39cd..763699c5af 100644 --- a/src/test/regress/sql/partition_split.sql +++ b/src/test/regress/sql/partition_split.sql @@ -42,7 +42,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-02-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); ---ERROR: list of split partitions should contains at least two items +--ERROR: list of split partitions should contain at least two items ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-10-01')); @@ -52,14 +52,14 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); --- ERROR: name "sales_feb_mar_apr2022" already used +-- ERROR: name "sales_feb_mar_apr2022" is already used -- (We can create partition with the same name as split partition, but can't create two partitions with the same name) ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_feb_mar_apr2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01')); --- ERROR: name "sales_feb2022" already used +-- ERROR: name "sales_feb2022" is already used ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_feb2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), @@ -77,7 +77,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-06-01')); --- ERROR: lower bound of partition "sales_mar2022" is not equals to upper bound of previous partition +-- ERROR: lower bound of partition "sales_mar2022" conflicts with upper bound of previous partition "sales_feb2022" ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-01') TO ('2022-03-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-02-01') TO ('2022-04-01'), @@ -86,7 +86,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO -- Tests for spaces between partitions, them should be executed without DEFAULT partition ALTER TABLE sales_range DETACH PARTITION sales_others; --- ERROR: lower bound of partition "sales_feb2022" is not equals to lower bound of split partition +-- ERROR: lower bound of partition "sales_feb2022" is not equal to lower bound of split partition ALTER TABLE sales_range SPLIT PARTITION sales_feb_mar_apr2022 INTO (PARTITION sales_feb2022 FOR VALUES FROM ('2022-02-02') TO ('2022-03-01'), PARTITION sales_mar2022 FOR VALUES FROM ('2022-03-01') TO ('2022-04-01'), @@ -133,7 +133,7 @@ SELECT * FROM sales_others; DROP TABLE sales_range CASCADE; -- --- Add split partition then add rows into partitioned table +-- Add split partition, then add rows into partitioned table -- CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date); CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01'); @@ -219,7 +219,7 @@ SELECT * FROM sales_jan_feb2022; DROP TABLE sales_date CASCADE; -- --- Test: split DEFAULT partition; using a index on partition key; check index after split +-- Test: split DEFAULT partition; use an index on partition key; check index after split -- CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date DATE) PARTITION BY RANGE (sales_date); CREATE TABLE sales_jan2022 PARTITION OF sales_range FOR VALUES FROM ('2022-01-01') TO ('2022-02-01'); @@ -250,7 +250,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO PARTITION sales_apr2022 FOR VALUES FROM ('2022-04-01') TO ('2022-05-01'), PARTITION sales_others DEFAULT); --- Use indexscan for test indexes +-- Use indexscan for testing indexes SET enable_indexscan = ON; SET enable_seqscan = OFF; @@ -270,7 +270,7 @@ SELECT * FROM pg_indexes WHERE tablename = 'sales_others' and schemaname = 'part DROP TABLE sales_range CASCADE; -- --- Test: some cases for split DEFAULT partition (different bounds) +-- Test: some cases for splitting DEFAULT partition (different bounds) -- CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date); CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; @@ -299,7 +299,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301), PARTITION sales_others DEFAULT); --- sales_error intersects with sales_dec2022 (exact the same bounds) +-- sales_error intersects with sales_dec2022 (exactly the same bounds) -- ERROR: lower bound of partition "sales_error" conflicts with upper bound of previous partition "sales_dec2022" ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101), @@ -313,7 +313,7 @@ ALTER TABLE sales_range SPLIT PARTITION sales_others INTO PARTITION sales_jan2022 FOR VALUES FROM (20220101) TO (20220201), PARTITION sales_feb2022 FOR VALUES FROM (20220201) TO (20220301)); --- no error: bounds of sales_noerror between sales_dec2022 and sales_feb2022 +-- no error: bounds of sales_noerror are between sales_dec2022 and sales_feb2022 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101), PARTITION sales_noerror FOR VALUES FROM (20220110) TO (20220120), @@ -325,7 +325,7 @@ DROP TABLE sales_range; CREATE TABLE sales_range (salesman_id INT, salesman_name VARCHAR(30), sales_amount INT, sales_date INT) PARTITION BY RANGE (sales_date); CREATE TABLE sales_others PARTITION OF sales_range DEFAULT; --- no error: bounds of sales_noerror equals to lower and upper bounds of sales_dec2022 and sales_feb2022 +-- no error: bounds of sales_noerror are equal to lower and upper bounds of sales_dec2022 and sales_feb2022 ALTER TABLE sales_range SPLIT PARTITION sales_others INTO (PARTITION sales_dec2022 FOR VALUES FROM (20211201) TO (20220101), PARTITION sales_noerror FOR VALUES FROM (20210101) TO (20210201), @@ -372,7 +372,7 @@ DROP TABLE sales_range CASCADE; DROP TABLE salesmans CASCADE; -- --- Test: split partition on partitioned table in case exists FOREIGN KEY reference from another table +-- Test: split partition on partitioned table in case of existing FOREIGN KEY reference from another table -- CREATE TABLE salesmans(salesman_id INT PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id); CREATE TABLE sales (salesman_id INT REFERENCES salesmans(salesman_id), sales_amount INT, sales_date DATE); @@ -470,12 +470,12 @@ DROP FUNCTION after_insert_row_trigger(); -- -- Test: split partition witch identity column --- If split partition column is identity-column, columns of new partitions are identity-columns too. +-- If split partition column is identity column, columns of new partitions are identity columns too. -- CREATE TABLE salesmans(salesman_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, salesman_name VARCHAR(30)) PARTITION BY RANGE (salesman_id); CREATE TABLE salesmans1_2 PARTITION OF salesmans FOR VALUES FROM (1) TO (2); --- Create new partition with identity-column: +-- Create new partition with identity column: CREATE TABLE salesmans2_5(salesman_id INT NOT NULL, salesman_name VARCHAR(30)); ALTER TABLE salesmans ATTACH PARTITION salesmans2_5 FOR VALUES FROM (2) TO (5); @@ -484,7 +484,7 @@ INSERT INTO salesmans (salesman_name) VALUES ('Ivanov'); SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans'::regclass::oid; SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans1_2'::regclass::oid; --- Split partition has identity-column: +-- Split partition has identity column: SELECT attname, attidentity, attgenerated FROM pg_attribute WHERE attnum > 0 AND attrelid = 'salesmans2_5'::regclass::oid; ALTER TABLE salesmans SPLIT PARTITION salesmans2_5 INTO @@ -631,8 +631,8 @@ DROP TABLE sales_list; -- -- Test: two specific errors for BY LIST partitioning: --- * new partitions not has NULL value that split partition has. --- * new partitions not has a value that split partition has. +-- * new partitions do not have NULL value, which split partition has. +-- * new partitions do not have a value that split partition has. -- CREATE TABLE sales_list (salesman_id INT, @@ -645,13 +645,13 @@ PARTITION BY LIST (sales_state); CREATE TABLE sales_nord PARTITION OF sales_list FOR VALUES IN ('Helsinki', 'St. Petersburg', 'Oslo'); CREATE TABLE sales_all PARTITION OF sales_list FOR VALUES IN ('Warsaw', 'Lisbon', 'New York', 'Madrid', 'Bejing', 'Berlin', 'Delhi', 'Kyiv', 'Vladivostok', NULL); --- ERROR: new partitions not have value NULL but split partition has +-- ERROR: new partitions do not have value NULL but split partition has ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'), PARTITION sales_central FOR VALUES IN ('Warsaw', 'Berlin', 'Kyiv')); --- ERROR: new partitions not have value 'Kyiv' but split partition has +-- ERROR: new partitions do not have value 'Kyiv' but split partition has ALTER TABLE sales_list SPLIT PARTITION sales_all INTO (PARTITION sales_west FOR VALUES IN ('Lisbon', 'New York', 'Madrid'), PARTITION sales_east FOR VALUES IN ('Bejing', 'Delhi', 'Vladivostok'), @@ -703,7 +703,7 @@ SELECT * FROM sales_east; SELECT * FROM sales_nord; SELECT * FROM sales_central; --- Use indexscan for test indexes after split partition +-- Use indexscan for testing indexes after splitting partition SET enable_indexscan = ON; SET enable_seqscan = OFF; -- 2.40.1.windows.1

view thread (298+ messages)  latest in thread

Message-ID: <86bfd241-a58c-479a-9a72-2c67a02becf8@postgrespro.ru>
Permalink:  ../86bfd241-a58c-479a-9a72-2c67a02becf8@postgrespro.ru/
Also on:    postgresql.org/message-id/86bfd241-a58c-479a-9a72-2c67a02becf8@postgrespro.ru

 ·  · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: d.koval@postgrespro.ru, exclusion@gmail.com, aekorotkov@gmail.com, pgsql-hackers@lists.postgresql.org, guofenglinux@gmail.com
  Subject: Re: Add SPLIT PARTITION/MERGE PARTITIONS commands
  In-Reply-To: <86bfd241-a58c-479a-9a72-2c67a02becf8@postgrespro.ru>

* 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