Hi,

The attached v1 reduces the median ATTACH PARTITION time from
276.664 ms to 29.837 ms with 1,600 NOT NULL columns.

ALTER TABLE ... INHERIT and ALTER TABLE ... ATTACH PARTITION call
MergeConstraintsIntoExisting(). For each CHECK or NOT NULL constraint
on the parent, the function scans the child's pg_constraint rows.
Since 14e87ffa5c5, each NOT NULL column has a pg_constraint row,
which makes this scan expensive on wide partitioned tables.

The patch looks up CHECK constraints by name using the existing
pg_constraint index. It reads the child's NOT NULL constraints once
and indexes them by the parent's attribute number.

I measured ATTACH with a child created using LIKE, a warm-up ATTACH,
synchronous_commit=off, and 20 rounds per width with alternating
build order. The baseline was c1dd701fb5f.

NOT NULL columns | Master (ms) | v1 (ms)
25 | 0.620 | 0.565
50 | 1.443 | 1.149
100 | 2.907 | 1.868
200 | 8.491 | 4.252
400 | 23.502 | 7.434
800 | 77.871 | 15.603
1600 | 276.664 | 29.837

Doubling the width from 800 to 1,600 columns increased the median
by 3.55x on master and 1.91x with v1.

For pg_upgrade --copy --no-sync from 18.6, v1 reduced total user-space
instructions by 15.1% on a synthetic schema with 1,000 partitions and
200 NOT NULL columns. On the smaller tier of David's schema [1], the
median paired reduction was 0.04% across three rounds (0.02% to 0.22%).
In a separate schema-restore profile per build, the inclusive share
of instruction samples in MergeConstraintsIntoExisting() went from
1.15% to 0.72% on that schema.

I also compared master and v1 on 25,000 generated inheritance and
partitioning cases. The error messages and resulting catalog rows
matched in every case, including 5,000 with ignore_system_indexes=on.

The attachments include the patch, its SHA-256 checksum, benchmark
scripts, and per-run data for the ATTACH curve and the four-build
comparison on David's schema.

[1] 
https://postgr.es/m/caaphdvqwnjmaqowh31d8qow9pozivzowd17vsgfpezdmcht...@mail.gmail.com

Regards,
Manu
From 4f986b7d3c2c2057a34f77e758f55b5ff4402352 Mon Sep 17 00:00:00 2001
From: Manu <[email protected]>
Date: Tue, 1 Dec 2026 02:10:29 -0300
Subject: [PATCH v1] Avoid quadratic behavior in MergeConstraintsIntoExisting()

ALTER TABLE ... INHERIT and ALTER TABLE ... ATTACH PARTITION call
MergeConstraintsIntoExisting(), which, for each CHECK and not-null
constraint of the parent, started a new scan over all pg_constraint
rows of the child.  That is O(N^2) in the number of constraints, as the
function's header comment has said since f58eac82eeb, and commit
b3f0e0503f3 described the function as "horribly inefficient" when
restoring tables with many inherited constraints.

Since 14e87ffa5c5 every not-null column has a pg_constraint row, so
this is no longer limited to tables with unusual numbers of CHECK
constraints: any wide table with NOT NULL columns hits it, and
pg_upgrade and pg_restore run one ATTACH PARTITION per partition.

Instead, look up each CHECK constraint of the parent in the child by
name, using the index on (conrelid, contypid, conname), and read the
child's not-null constraints only once, into an array indexed by the
parent's attribute number (through the existing attribute map).  The
checks applied to a matching pair, the error messages and the order in
which errors are raised are unchanged.

Attaching one partition to a table with 1600 NOT NULL columns goes
from about 280 ms to 36 ms, and pg_upgrade of a table with 1000
partitions and 200 NOT NULL columns executes 15% fewer instructions.

Author: Manu <[email protected]>
---
 src/backend/commands/tablecmds.c | 252 ++++++++++++++++++-------------
 1 file changed, 144 insertions(+), 108 deletions(-)

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index 9e363a44c20..a2f83ef8252 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -18953,9 +18953,9 @@ MergeAttributesIntoExisting(Relation child_rel, Relation parent_rel, bool ispart
  * Currently all constraints in parent must be present in the child. One day we
  * may consider adding new constraints like CREATE TABLE does.
  *
- * XXX This is O(N^2) which may be an issue with tables with hundreds of
- * constraints. As long as tables have more like 10 constraints it shouldn't be
- * a problem though. Even 100 constraints ought not be the end of the world.
+ * To keep the cost from growing with the product of the number of
+ * constraints of both tables, each CHECK constraint is looked up by name in
+ * the child, and the child's not-null constraints are read only once.
  *
  * XXX See MergeWithExistingConstraint too if you change this code.
  */
@@ -18968,6 +18968,7 @@ MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel)
 	HeapTuple	parent_tuple;
 	Oid			parent_relid = RelationGetRelid(parent_rel);
 	AttrMap    *attmap;
+	HeapTuple  *child_notnulls = NULL;	/* indexed by parent attnum */
 
 	constraintrel = table_open(ConstraintRelationId, RowExclusiveLock);
 
@@ -18986,11 +18987,8 @@ MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel)
 	while (HeapTupleIsValid(parent_tuple = systable_getnext(parent_scan)))
 	{
 		Form_pg_constraint parent_con = (Form_pg_constraint) GETSTRUCT(parent_tuple);
-		SysScanDesc child_scan;
-		ScanKeyData child_key;
+		Form_pg_constraint child_con;
 		HeapTuple	child_tuple;
-		AttrNumber	parent_attno;
-		bool		found = false;
 
 		if (parent_con->contype != CONSTRAINT_CHECK &&
 			parent_con->contype != CONSTRAINT_NOTNULL)
@@ -19000,126 +18998,100 @@ MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel)
 		if (parent_con->connoinherit)
 			continue;
 
-		if (parent_con->contype == CONSTRAINT_NOTNULL)
-			parent_attno = extractNotNullColumn(parent_tuple);
-		else
-			parent_attno = InvalidAttrNumber;
+		/*
+		 * Search for a child constraint matching this one.  CHECK constraints
+		 * are matched by constraint name, NOT NULL ones by attribute number.
+		 */
+		if (parent_con->contype == CONSTRAINT_CHECK)
+		{
+			SysScanDesc child_scan;
+			ScanKeyData child_key[3];
 
-		/* Search for a child constraint matching this one */
-		ScanKeyInit(&child_key,
-					Anum_pg_constraint_conrelid,
-					BTEqualStrategyNumber, F_OIDEQ,
-					ObjectIdGetDatum(RelationGetRelid(child_rel)));
-		child_scan = systable_beginscan(constraintrel, ConstraintRelidTypidNameIndexId,
-										true, NULL, 1, &child_key);
+			ScanKeyInit(&child_key[0],
+						Anum_pg_constraint_conrelid,
+						BTEqualStrategyNumber, F_OIDEQ,
+						ObjectIdGetDatum(RelationGetRelid(child_rel)));
+			ScanKeyInit(&child_key[1],
+						Anum_pg_constraint_contypid,
+						BTEqualStrategyNumber, F_OIDEQ,
+						ObjectIdGetDatum(InvalidOid));
+			ScanKeyInit(&child_key[2],
+						Anum_pg_constraint_conname,
+						BTEqualStrategyNumber, F_NAMEEQ,
+						NameGetDatum(&parent_con->conname));
+			child_scan = systable_beginscan(constraintrel, ConstraintRelidTypidNameIndexId,
+											true, NULL, 3, child_key);
+
+			/* There can be at most one matching row */
+			child_tuple = systable_getnext(child_scan);
+			if (HeapTupleIsValid(child_tuple) &&
+				((Form_pg_constraint) GETSTRUCT(child_tuple))->contype == CONSTRAINT_CHECK)
+				child_tuple = heap_copytuple(child_tuple);
+			else
+				child_tuple = NULL;
 
-		while (HeapTupleIsValid(child_tuple = systable_getnext(child_scan)))
+			systable_endscan(child_scan);
+		}
+		else
 		{
-			Form_pg_constraint child_con = (Form_pg_constraint) GETSTRUCT(child_tuple);
-			HeapTuple	child_copy;
-
-			if (child_con->contype != parent_con->contype)
-				continue;
+			AttrNumber	parent_attno = extractNotNullColumn(parent_tuple);
 
 			/*
-			 * CHECK constraint are matched by constraint name, NOT NULL ones
-			 * by attribute number.
+			 * The first time, collect the child's not-null constraints on
+			 * columns that are NOT NULL in the parent, by parent column.  We
+			 * keep copies of the tuples as they are now: the updates made
+			 * below are not visible to scans within this command anyway.
 			 */
-			if (child_con->contype == CONSTRAINT_CHECK)
+			if (child_notnulls == NULL)
 			{
-				if (strcmp(NameStr(parent_con->conname),
-						   NameStr(child_con->conname)) != 0)
-					continue;
-			}
-			else if (child_con->contype == CONSTRAINT_NOTNULL)
-			{
-				Form_pg_attribute parent_attr;
-				Form_pg_attribute child_attr;
-				AttrNumber	child_attno;
+				SysScanDesc child_scan;
+				ScanKeyData child_key;
 
-				parent_attr = TupleDescAttr(parent_rel->rd_att, parent_attno - 1);
-				child_attno = extractNotNullColumn(child_tuple);
-				if (parent_attno != attmap->attnums[child_attno - 1])
-					continue;
+				child_notnulls = palloc0_array(HeapTuple,
+											   RelationGetNumberOfAttributes(parent_rel) + 1);
 
-				child_attr = TupleDescAttr(child_rel->rd_att, child_attno - 1);
-				/* there shouldn't be constraints on dropped columns */
-				if (parent_attr->attisdropped || child_attr->attisdropped)
-					elog(ERROR, "found not-null constraint on dropped columns");
-			}
-
-			if (child_con->contype == CONSTRAINT_CHECK &&
-				!constraints_equivalent(parent_tuple, child_tuple, RelationGetDescr(constraintrel)))
-				ereport(ERROR,
-						(errcode(ERRCODE_DATATYPE_MISMATCH),
-						 errmsg("child table \"%s\" has different definition for check constraint \"%s\"",
-								RelationGetRelationName(child_rel), NameStr(parent_con->conname))));
+				ScanKeyInit(&child_key,
+							Anum_pg_constraint_conrelid,
+							BTEqualStrategyNumber, F_OIDEQ,
+							ObjectIdGetDatum(RelationGetRelid(child_rel)));
+				child_scan = systable_beginscan(constraintrel, ConstraintRelidTypidNameIndexId,
+												true, NULL, 1, &child_key);
 
-			/*
-			 * If the child constraint is "no inherit" then cannot merge
-			 */
-			if (child_con->connoinherit)
-				ereport(ERROR,
-						(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-						 errmsg("constraint \"%s\" conflicts with non-inherited constraint on child table \"%s\"",
-								NameStr(child_con->conname), RelationGetRelationName(child_rel))));
+				while (HeapTupleIsValid(child_tuple = systable_getnext(child_scan)))
+				{
+					AttrNumber	child_parent_attno;
 
-			/*
-			 * If the child constraint is "not valid" then cannot merge with a
-			 * valid parent constraint
-			 */
-			if (parent_con->convalidated && child_con->conenforced &&
-				!child_con->convalidated)
-				ereport(ERROR,
-						(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-						 errmsg("constraint \"%s\" conflicts with NOT VALID constraint on child table \"%s\"",
-								NameStr(child_con->conname), RelationGetRelationName(child_rel))));
+					child_con = (Form_pg_constraint) GETSTRUCT(child_tuple);
+					if (child_con->contype != CONSTRAINT_NOTNULL)
+						continue;
 
-			/*
-			 * A NOT ENFORCED child constraint cannot be merged with an
-			 * ENFORCED parent constraint. However, the reverse is allowed,
-			 * where the child constraint is ENFORCED.
-			 */
-			if (parent_con->conenforced && !child_con->conenforced)
-				ereport(ERROR,
-						(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
-						 errmsg("constraint \"%s\" conflicts with NOT ENFORCED constraint on child table \"%s\"",
-								NameStr(child_con->conname), RelationGetRelationName(child_rel))));
+					child_parent_attno = attmap->attnums[extractNotNullColumn(child_tuple) - 1];
+					if (child_parent_attno > 0 &&
+						TupleDescAttr(parent_rel->rd_att, child_parent_attno - 1)->attnotnull &&
+						child_notnulls[child_parent_attno] == NULL)
+						child_notnulls[child_parent_attno] = heap_copytuple(child_tuple);
+				}
 
-			/*
-			 * OK, bump the child constraint's inheritance count.  (If we fail
-			 * later on, this change will just roll back.)
-			 */
-			child_copy = heap_copytuple(child_tuple);
-			child_con = (Form_pg_constraint) GETSTRUCT(child_copy);
+				systable_endscan(child_scan);
+			}
 
-			if (pg_add_s16_overflow(child_con->coninhcount, 1,
-									&child_con->coninhcount))
-				ereport(ERROR,
-						errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
-						errmsg("too many inheritance parents"));
+			child_tuple = child_notnulls[parent_attno];
 
-			/*
-			 * In case of partitions, an inherited constraint must be
-			 * inherited only once since it cannot have multiple parents and
-			 * it is never considered local.
-			 */
-			if (parent_rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
+			if (HeapTupleIsValid(child_tuple))
 			{
-				Assert(child_con->coninhcount == 1);
-				child_con->conislocal = false;
-			}
-
-			CatalogTupleUpdate(constraintrel, &child_copy->t_self, child_copy);
-			heap_freetuple(child_copy);
+				Form_pg_attribute parent_attr;
+				Form_pg_attribute child_attr;
 
-			found = true;
-			break;
+				parent_attr = TupleDescAttr(parent_rel->rd_att, parent_attno - 1);
+				child_attr = TupleDescAttr(child_rel->rd_att,
+										   extractNotNullColumn(child_tuple) - 1);
+				/* there shouldn't be constraints on dropped columns */
+				if (parent_attr->attisdropped || child_attr->attisdropped)
+					elog(ERROR, "found not-null constraint on dropped columns");
+			}
 		}
 
-		systable_endscan(child_scan);
-
-		if (!found)
+		if (!HeapTupleIsValid(child_tuple))
 		{
 			if (parent_con->contype == CONSTRAINT_NOTNULL)
 				ereport(ERROR,
@@ -19135,6 +19107,70 @@ MergeConstraintsIntoExisting(Relation child_rel, Relation parent_rel)
 					 errmsg("child table is missing constraint \"%s\"",
 							NameStr(parent_con->conname))));
 		}
+
+		child_con = (Form_pg_constraint) GETSTRUCT(child_tuple);
+
+		if (child_con->contype == CONSTRAINT_CHECK &&
+			!constraints_equivalent(parent_tuple, child_tuple, RelationGetDescr(constraintrel)))
+			ereport(ERROR,
+					(errcode(ERRCODE_DATATYPE_MISMATCH),
+					 errmsg("child table \"%s\" has different definition for check constraint \"%s\"",
+							RelationGetRelationName(child_rel), NameStr(parent_con->conname))));
+
+		/*
+		 * If the child constraint is "no inherit" then cannot merge
+		 */
+		if (child_con->connoinherit)
+			ereport(ERROR,
+					(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+					 errmsg("constraint \"%s\" conflicts with non-inherited constraint on child table \"%s\"",
+							NameStr(child_con->conname), RelationGetRelationName(child_rel))));
+
+		/*
+		 * If the child constraint is "not valid" then cannot merge with a
+		 * valid parent constraint
+		 */
+		if (parent_con->convalidated && child_con->conenforced &&
+			!child_con->convalidated)
+			ereport(ERROR,
+					(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+					 errmsg("constraint \"%s\" conflicts with NOT VALID constraint on child table \"%s\"",
+							NameStr(child_con->conname), RelationGetRelationName(child_rel))));
+
+		/*
+		 * A NOT ENFORCED child constraint cannot be merged with an ENFORCED
+		 * parent constraint. However, the reverse is allowed, where the child
+		 * constraint is ENFORCED.
+		 */
+		if (parent_con->conenforced && !child_con->conenforced)
+			ereport(ERROR,
+					(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
+					 errmsg("constraint \"%s\" conflicts with NOT ENFORCED constraint on child table \"%s\"",
+							NameStr(child_con->conname), RelationGetRelationName(child_rel))));
+
+		/*
+		 * OK, bump the child constraint's inheritance count.  (If we fail
+		 * later on, this change will just roll back.)  The tuple is our own
+		 * copy, so we can scribble on it.
+		 */
+		if (pg_add_s16_overflow(child_con->coninhcount, 1,
+								&child_con->coninhcount))
+			ereport(ERROR,
+					errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
+					errmsg("too many inheritance parents"));
+
+		/*
+		 * In case of partitions, an inherited constraint must be inherited
+		 * only once since it cannot have multiple parents and it is never
+		 * considered local.
+		 */
+		if (parent_rel->rd_rel->relkind == RELKIND_PARTITIONED_TABLE)
+		{
+			Assert(child_con->coninhcount == 1);
+			child_con->conislocal = false;
+		}
+
+		CatalogTupleUpdate(constraintrel, &child_tuple->t_self, child_tuple);
 	}
 
 	systable_endscan(parent_scan);

base-commit: c1dd701fb5f866fbab78dcd33b184e2fb7a4782d
-- 
2.56.1

MergeConstraintsIntoExisting() patch: measurements
==================================================

master:  c1dd701fb5f (2026-11-29), make -O2 -g, no cassert
patched: same plus v1-0001
old cluster for pg_upgrade: REL_18_STABLE 18.6, same flags
Runs alternate between master and patched.  "instr" = user-space
instructions (perf stat -e instructions:u).  The 95% confidence
interval is a bootstrap of the change in the median.

1. ATTACH PARTITION, parent with N NOT NULL columns, child created
   with LIKE.  attach-bench.sh.txt curve 20: 20 runs per build and N,
   synchronous_commit=off, time from psql's \timing.  One fresh
   cluster per round and build runs every N, after one unmeasured
   ATTACH; the build that goes first alternates between rounds.

      N   master ms   patched ms   change   95% CI
     25        0.62         0.56    -8.9%   -10.6 ..  -4.1%
     50        1.44         1.15   -20.3%   -21.9 .. -17.7%
    100        2.91         1.87   -35.8%   -37.3 .. -34.5%
    200        8.49         4.25   -49.9%   -50.8 .. -48.0%
    400       23.50         7.43   -68.4%   -69.4 .. -67.1%
    800       77.87        15.60   -80.0%   -80.4 .. -79.3%
   1600      276.66        29.84   -89.2%   -89.4 .. -88.7%

   Local exponent of the median, log(t2/t1) / log(N2/N1):

   N1 -> N2      master   patched
     25 -> 50      1.22      1.02
     50 -> 100     1.01      0.70
    100 -> 200     1.55      1.19
    200 -> 400     1.47      0.81
    400 -> 800     1.73      1.07
    800 -> 1600    1.83      0.94

   Every cell has one mode.  At most two runs per cell are more than
   30% above its median (the largest, 1.96 times).

2. ATTACH/DETACH x 200, parent with 1 CHECK.  attach-bench.sh.txt
   checks 3 (instr of the whole server)

   child CHECKs   round   master M   patched M
   1601           1       6002.3     6001.7
   1601           2       6002.2     6001.7
   1601           3       6002.3     6001.7
   1              1        592.6      594.1
   1              2        592.6      593.8
   1              3        592.6      593.8

3. pg_upgrade --copy --no-sync from 18.6, schema "wide" (one table,
   1000 partitions, 200 NOT NULL columns plus a primary key, no rows).
   pg_upgrade-bench.sh.txt wide 9; instr of the whole pg_upgrade
   process tree.

   instr G:  master median 512.31, patched 434.84: -15.1%
             (95% CI -15.1 .. -15.1), the same in all nine rounds
   wall s:   master  32.7 34.6 36.4 37.2 38.5 39.3 41.3 47.0 61.0
             patched 28.0 31.3 35.1 37.9 39.3 47.2 48.6 55.5 77.7
             change of the median +2.1% (95% CI -18.7 .. +40.6):
             the interval crosses zero, so there is no wall clock
             result.

4. pg_upgrade --copy from 18.6, schema "tom" (the case from the
   b3f0e0503f3 thread: 100 tables x 1000 CHECK constraints, each with
   one INHERITS child).  pg_upgrade-bench.sh.txt tom 3; instr.

   round   master G    patched G
   1       12395.29    12197.88
   2       12395.32    12197.98
   3       12395.28    12198.07

5. Restore of the "tom" case cut to 10 tables, split by command.
   restore-split.sh.txt 3 (pg_dump --binary-upgrade, restore with
   log_min_duration_statement = 0; seconds summed per command kind)

   round  build     instr G   wall s   ADD CONSTRAINT s   INHERIT s
   1      master     192.10    104.7        97.5             4.48
   1      patched    162.45     98.7        94.0             1.88
   2      master     192.10     96.1        89.1             4.37
   2      patched    162.45     90.5        86.1             1.86
   3      master     192.10     89.9        83.8             3.82
   3      patched    162.45     98.9        93.7             2.09

6. pg_upgrade --copy --no-sync on the smaller tier of David Rowley's
   partition and foreign-key schema, with 91,678 pg_class rows.
   Both clusters were 20devel. The source used master at 9cd6fe0d0ab
   throughout. The four destination builds used that same base, with
   MergeConstraints, the FK constraint-name patch (#118 v1), or both.
   Runs used tmpfs and three rounds with rotated build order. All 12
   upgrades completed.

   Build             Total instr G    Paired change    Total wall s
   Master                   530.46                -          43.524
   MergeConstraints         530.19           -0.04%          43.469
   #118                     522.66           -1.50%          43.480
   Both                     522.48           -1.62%          42.856

   Instruction counts and wall times are medians. Paired changes
   are medians of the changes relative to master within each round.
   The MergeConstraints-only reductions ranged from 0.02% to 0.22%.

   Separate perf profiles (one per build) estimated the inclusive
   share of user-space instruction samples during schema restore.

   Build             MergeConstraintsIntoExisting
   Master                                    1.15%
   MergeConstraints                          0.72%
   #118                                      0.91%
   Both                                      0.56%
#!/usr/bin/env bash
# ATTACH PARTITION on two builds (master and patched), alternating rounds.
#
#   MASTERBIN=... PATCHEDBIN=... WORKDIR=... attach-bench.sh <case> <rounds>
#
# case "curve":   for N in $NS (default 25 50 100 200 400 800 1600): parent with
#                 N NOT NULL int columns, child created with LIKE, one ATTACH
#                 PARTITION in a new session, time reported by psql's \timing.
#                 One fresh cluster per round and build, started with
#                 synchronous_commit=off so that the time is the work of the
#                 command and not the WAL flush at commit; one unmeasured
#                 ATTACH of a one-column table first, so that no N pays for
#                 the first ATTACH in the cluster.  The build that goes first
#                 alternates between rounds.
# case "checks":  parent with one CHECK constraint, child with that CHECK plus
#                 1600 more ("checks"), or with only that one ("checks0");
#                 200 ATTACH/DETACH cycles in one DO block, user-space
#                 instructions of the whole server (perf stat).
set -uo pipefail
C=$1 N=$2
: "${MASTERBIN:?} ${PATCHEDBIN:?} ${WORKDIR:?}"
W=$WORKDIR/attach-$C; mkdir -p "$W"; cd "$W" || exit 1
PORT=54841
sql() { "$B/psql" -X -q -h "$W" -p $PORT -U postgres -d postgres -v 
ON_ERROR_STOP=1 "$@"; }
fresh() {
  rm -rf data; "$B/initdb" -D data -U postgres -A trust >/dev/null || exit 1
}
setup_checks() {  # $1 = number of extra CHECK constraints on the child
  sql <<SQL
CREATE TABLE p (a int, b int CONSTRAINT k0 CHECK (b > 0)) PARTITION BY RANGE 
(a);
SELECT format('CREATE TABLE s (a int, b int CONSTRAINT k0 CHECK (b > 0)%s)',
              coalesce(string_agg(format(', CONSTRAINT k%s CHECK (b > -%s)', i, 
i), ''), ''))
FROM generate_series(1, $1) i \gexec
SQL
}
NS=${NS:-25 50 100 200 400 800 1600}
for r in $(seq 1 "$N"); do
  order="master patched"; [ "$C" = curve ] && [ $((r % 2)) = 0 ] && 
order="patched master"
  for b in $order; do
    [ $b = master ] && B=$MASTERBIN || B=$PATCHEDBIN
    if [ "$C" = curve ]; then
      fresh
      "$B/pg_ctl" -D data -o "-k $W -p $PORT -c synchronous_commit=off" -l 
server.log -w start >/dev/null
      sql -c 'CREATE TABLE w (c1 int NOT NULL) PARTITION BY RANGE (c1)' -c 
'CREATE TABLE ws (LIKE w)' \
          -c 'ALTER TABLE w ATTACH PARTITION ws FOR VALUES FROM (0) TO (10)'
      for n in $NS; do
        ms=$(sql <<SQL | awk '/^Time:/{print $2}'
SELECT format('CREATE TABLE p$n (%s) PARTITION BY RANGE (c1)',
              string_agg(format('c%s int NOT NULL', i), ', '))
FROM generate_series(1, $n) i \gexec
CREATE TABLE s$n (LIKE p$n);
\timing on
ALTER TABLE p$n ATTACH PARTITION s$n FOR VALUES FROM (0) TO (10);
SQL
)
        printf '%s\tround=%d\t%s\tN=%d\tattach_ms=%s\n' "$C" "$r" $b "$n" "$ms"
      done
      "$B/pg_ctl" -D data -m fast -w stop >/dev/null
    else
      for k in 1600 0; do
        fresh
        "$B/pg_ctl" -D data -o "-k $W -p $PORT" -l server.log -w start 
>/dev/null
        setup_checks $k
        "$B/pg_ctl" -D data -m fast -w stop >/dev/null
        perf stat -x, -e instructions:u -o perf.txt -- "$B/postgres" -D data -k 
"$W" -p $PORT \
          > server.log 2>&1 &
        until "$B/pg_isready" -q -h "$W" -p $PORT; do sleep 0.2; done
        n=$(sql -At <<'SQL' | tail -1
DO $$ BEGIN
  FOR i IN 1..200 LOOP
    ALTER TABLE p ATTACH PARTITION s FOR VALUES FROM (0) TO (10);
    ALTER TABLE p DETACH PARTITION s;
  END LOOP;
END $$;
SELECT count(*) FROM pg_constraint WHERE conrelid = 's'::regclass;
SQL
)
        "$B/pg_ctl" -D data -m fast -w stop >/dev/null; wait
        printf '%s\tround=%d\t%s\tchild_checks=%s\tinstr_M=%.1f\n' "checks$([ 
$k = 0 ] && echo 0)" \
          "$r" $b "$n" "$(awk -F, '/instructions/{print $1/1e6}' perf.txt)"
      done
    fi
  done
done
#!/usr/bin/env bash
# pg_upgrade from an old release to two builds of the new one (master and 
patched),
# schema only, alternating rounds.  Prints one line per run with the user-space 
instructions
# of the whole pg_upgrade process tree (pg_dump, restore and both servers; perf 
stat) and the
# wall clock time.  The instruction count is the stable figure: the wall clock 
includes
# copying and syncing files, which depends on whatever else the disk is doing.
#
#   OLDBIN=... MASTERBIN=... PATCHEDBIN=... WORKDIR=... pg_upgrade-bench.sh 
<schema> <rounds>
#
# Optional: EXTRABIN=<bindir> EXTRALABEL=<name> adds a third build; 
UPGRADE_OPTS is passed
# to pg_upgrade (for example --no-sync).  The order of the builds rotates 
between rounds.
#
# schema "wide": one range-partitioned table, 1000 partitions x 200 NOT NULL 
int columns
#                and a primary key
# schema "tom":  the case from the b3f0e0503f3 thread, 100 tables x 1000
#                "float check (a > 10.2)" columns, each with one INHERITS child
set -uo pipefail
S=$1 N=$2
: "${OLDBIN:?} ${MASTERBIN:?} ${PATCHEDBIN:?} ${WORKDIR:?}"
W=$WORKDIR/$S
mkdir -p "$W"; cd "$W" || exit 1
gen() {
  if [ "$S" = wide ]; then
    cols=$(seq -s, -f 'c%g int not null' 1 200)
    echo "create table p (id int not null, $cols, primary key (id)) partition 
by range (id);"
    for i in $(seq 0 999); do
      echo "create table p$i partition of p for values from ($((i*10))) to 
($((i*10+10)));"
    done
  else
    for i in $(seq 0 99); do
      echo "CREATE TABLE test_inh_check$i ("
      for j in $(seq 0 999); do echo "a$j float check (a$j > 10.2),"; done
      echo "b float);"
      echo "CREATE TABLE test_inh_check_child$i() INHERITS(test_inh_check$i);"
    done
  fi
}
if [ ! -f "$W/old/PG_VERSION" ]; then
  "$OLDBIN"/initdb -D "$W/old" -U postgres -A trust >/dev/null || exit 1
  "$OLDBIN"/pg_ctl -D "$W/old" -o "-p 54811 -k $W -c 
max_locks_per_transaction=1024" \
    -l "$W/old.log" -w start >/dev/null
  gen > "$W/schema.sql"
  "$OLDBIN"/psql -X -q -h "$W" -p 54811 -U postgres -d postgres -v 
ON_ERROR_STOP=1 \
    -f "$W/schema.sql" || exit 1
  "$OLDBIN"/psql -X -At -h "$W" -p 54811 -U postgres -d postgres -c \
    "select 'old: '||version()||' | constraints='||count(*) from pg_constraint
     where connamespace='public'::regnamespace"
  "$OLDBIN"/pg_ctl -D "$W/old" -w stop >/dev/null
fi
labels=(master patched); bins=("$MASTERBIN" "$PATCHEDBIN")
[ -n "${EXTRABIN:-}" ] && { labels+=("${EXTRALABEL:-extra}"); 
bins+=("$EXTRABIN"); }
nb=${#labels[@]}
for r in $(seq 1 "$N"); do
  for k in $(seq 0 $((nb - 1))); do
    i=$(( (k + r - 1) % nb )); b=${labels[$i]}; B=${bins[$i]}
    rm -rf "$W/new-$b" "$W/run-$b"; mkdir -p "$W/run-$b"
    "$B"/initdb -D "$W/new-$b" -U postgres -A trust >/dev/null || exit 1
    cd "$W/run-$b"
    t0=$(date +%s.%N)
    perf stat -x, -e instructions:u -o "$W/run-$b/perf.txt" -- \
    "$B"/pg_upgrade -U postgres -b "$OLDBIN" -B "$B" -d "$W/old" -D "$W/new-$b" 
\
      -p 54811 -P 54812 -s "$W" --copy ${UPGRADE_OPTS:-} > "$W/run-$b/out.txt" 
2>&1
    rc=$?
    t1=$(date +%s.%N)
    cd "$W"
    grep -q 'Upgrade Complete' "$W/run-$b/out.txt" || rc="$rc(no 'Upgrade 
Complete')"
    ins=$(awk -F, '/instructions/{print $1}' "$W/run-$b/perf.txt")
    printf '%s\tround=%d\t%s\texit=%s\tinstr_G=%.2f\twall_s=%.2f\n' "$S" "$r" 
$b "$rc" \
      "$(echo "$ins/1000000000" | bc -l)" "$(echo "$t1 - $t0" | bc)"
  done
done
#!/usr/bin/env bash
# Where does the restore of Tom's case go?  The case from the b3f0e0503f3 
thread, cut to 10
# tables (10 x 1000 inherited CHECK constraints), is dumped with pg_dump 
--binary-upgrade from
# the old release and restored into master and into patched, alternating 
rounds.  For each
# restore it prints the user-space instructions of the whole server (perf 
stat), the wall
# clock, and the summed server-side duration of the ADD CONSTRAINT statements, 
of the
# INHERIT statements (the only ones that run MergeConstraintsIntoExisting) and 
of the rest.
#
#   OLDBIN=... MASTERBIN=... PATCHEDBIN=... WORKDIR=... restore-split.sh 
<rounds>
set -uo pipefail
N=$1
: "${OLDBIN:?} ${MASTERBIN:?} ${PATCHEDBIN:?} ${WORKDIR:?}"
W=$WORKDIR/split
mkdir -p "$W"; cd "$W" || exit 1
rm -rf old new-* ./*.log ./*.sql ./*.perf
"$OLDBIN"/initdb -D old -U postgres -A trust >/dev/null || exit 1
"$OLDBIN"/pg_ctl -D old -o "-p 54821 -k $W" -l old.log -w start >/dev/null
for i in $(seq 0 9); do
  echo "CREATE TABLE test_inh_check$i ("
  for j in $(seq 0 999); do echo "a$j float check (a$j > 10.2),"; done
  echo "b float);"
  echo "CREATE TABLE test_inh_check_child$i() INHERITS(test_inh_check$i);"
done > schema.sql
"$OLDBIN"/psql -X -q -h "$W" -p 54821 -U postgres -d postgres -v 
ON_ERROR_STOP=1 -f schema.sql
"$MASTERBIN"/pg_dump -h "$W" -p 54821 -U postgres --schema-only 
--binary-upgrade \
  -f dump.sql postgres
"$OLDBIN"/pg_ctl -D old -w stop >/dev/null
for r in $(seq 1 "$N"); do
  for b in master patched; do
    if [ $b = master ]; then B=$MASTERBIN; else B=$PATCHEDBIN; fi
    rm -rf "new-$b"; "$B"/initdb -D "new-$b" -U postgres -A trust >/dev/null
    perf stat -e instructions:u -x, -o "$b-$r.perf" -- "$B"/postgres -D 
"$W/new-$b" \
      -p 54822 -k "$W" -b -c log_min_duration_statement=0 -c log_line_prefix= \
      > "$b-$r.log" 2>&1 &
    until "$B"/pg_isready -q -h "$W" -p 54822; do sleep 0.2; done
    t0=$(date +%s.%N)
    "$B"/psql -X -q -o /dev/null -h "$W" -p 54822 -U postgres -d postgres \
      -v ON_ERROR_STOP=1 -f dump.sql
    t1=$(date +%s.%N)
    "$B"/pg_ctl -D "new-$b" -m fast -w stop >/dev/null; wait
    ins=$(awk -F, '/instructions/{print $1}' "$b-$r.perf")
    k=$(awk '/duration: .* ms +statement: /{d=$3
               if ($0 ~ / INHERIT /) i+=d; else if ($0 ~ /ADD CONSTRAINT/) 
a+=d; else o+=d}
             END{printf "addcon_s=%.2f\tinherit_s=%.2f\tother_s=%.2f", a/1000, 
i/1000, o/1000}' \
        "$b-$r.log")
    printf 'tom10\tround=%d\t%s\tinstr_G=%.3f\twall_s=%.2f\t%s\n' "$r" $b \
      "$(echo "$ins/1000000000" | bc -l)" "$(echo "$t1 - $t0" | bc)" "$k"
  done
done
#!/usr/bin/env python3
"""Differential oracle for MergeConstraintsIntoExisting(): random parent/child 
schemas,
then ALTER TABLE ... INHERIT / ATTACH PARTITION; the output is every error 
message and
the resulting catalog rows.  Run it with the same seeds against a master server 
and a
patched server (any build) and compare the two files: they must be identical.

  oracle.py run BINDIR WORKDIR OUT SEED0 NSEEDS [PORT]
  oracle.py sql SEED                      print the SQL of one case
  oracle.py summary OUT                   outcome classes of the target 
statements
  oracle.py compare OUT_A OUT_B           per-case comparison; exit 1 if any 
case differs

What a case mixes: NOT NULL (plain, named, NO INHERIT, NOT VALID), CHECK (same 
or different
definition, NO INHERIT, NOT VALID, NOT ENFORCED), names that collide across 
kinds, child
columns in another order, dropped columns, extra and missing child constraints 
and
columns; plain inheritance, partitions, two parents, a re-attach after detach, 
a child that
is itself partitioned or has its own inheritance child.
"""
import os, random, re, subprocess, sys

COLS = ['a', 'b', 'c', 'd', 'e', 'f', 'g']
EXPRS = ['{c} > 0', '{c} < 100', '{c} <> 5', '{c} IS NOT NULL', '{c} + 1 > 0']
MODES = ['inherit', 'attach', 'multi', 'subpart', 'reattach', 'reinherit', 
'grand']
DUMP = """SELECT c.relname, con.conname, con.contype, con.coninhcount, 
con.conislocal, con.connoinherit,
       con.convalidated, con.conenforced, con.conkey, 
pg_get_constraintdef(con.oid)
FROM pg_constraint con JOIN pg_class c ON c.oid = con.conrelid
WHERE c.relnamespace = 'o'::regnamespace ORDER BY 1, 2;
SELECT c.relname, a.attname, a.attnum, a.attnotnull, a.attinhcount, a.attislocal
FROM pg_attribute a JOIN pg_class c ON c.oid = a.attrelid
WHERE c.relnamespace = 'o'::regnamespace AND c.relkind IN ('r', 'p') AND 
a.attnum > 0 ORDER BY 1, 3;
SELECT inhrelid::regclass, inhparent::regclass, inhseqno FROM pg_inherits
WHERE inhparent::regclass::text ~ '^(o\\.)?(p|p2|s)$' ORDER BY 1, 2;"""


def nn_clause(r, table, col, allow_noinherit, names):
    """(inline clause, later statements) for a not-null constraint on col."""
    k = r.random()
    if k < 0.55:
        return ' NOT NULL', []
    if k < 0.80:
        nm = r.choice(names) if r.random() < 0.12 else r.choice([f'nn_{col}', 
f'{table}_{col}_x'])
        return f' CONSTRAINT {nm} NOT NULL', []
    if k < 0.90 and allow_noinherit:
        return ' NOT NULL NO INHERIT', []
    if k < 0.97:
        nm = r.choice(names) if r.random() < 0.1 else f'nv_{col}'
        return '', [f'ALTER TABLE {table} ADD CONSTRAINT {nm} NOT NULL {col} 
NOT VALID']
    return ' NOT NULL', []


def flags(r, allow_noinherit, p_ni=0.08, p_nv=0.08, p_ne=0.08):
    k = r.random()
    if k < p_ni and allow_noinherit:
        return ' NO INHERIT'
    if k < p_ni + p_nv:
        return ' NOT VALID'
    if k < p_ni + p_nv + p_ne:
        return ' NOT ENFORCED'
    return ''


def table(r, name, cols, nn, checks, partby=None, order=None, extra=0, 
predrop=False):
    """CREATE TABLE and follow-up statements.  nn: {col: (clause, later)}; 
checks: [(name, expr, flags)]."""
    order = order or cols
    defs, later = [], []
    if predrop:
        defs.append('zz int')
    for c in order:
        cl, lt = nn.get(c, ('', []))
        defs.append(f'{c} int{cl}')
        later += lt
    for i in range(extra):
        defs.append(f'x{i} int' + (' NOT NULL' if r.random() < 0.5 else ''))
    inline = [f'CONSTRAINT {n} CHECK ({e}){f}' for n, e, f in checks if f != ' 
NOT VALID']
    later += [f'ALTER TABLE {name} ADD CONSTRAINT {n} CHECK ({e}) NOT VALID' 
for n, e, f in checks
              if f == ' NOT VALID']
    st = [f'CREATE TABLE {name} ({", ".join(defs + inline)})' + (f' PARTITION 
BY RANGE ({partby})' if partby else '')]
    if predrop:
        st.append(f'ALTER TABLE {name} DROP COLUMN zz')
    return st + later


def case(seed):
    r = random.Random(seed)
    mode = r.choice(MODES)
    parted = mode in ('attach', 'subpart', 'reattach')
    cols = r.sample(COLS, r.randint(1, 6))
    cknames = [f'k{i}' for i in range(1, 5)]
    # parent
    pnn = {c: nn_clause(r, 'p', c, not parted, cknames) for c in cols if 
r.random() < 0.6}
    pchecks = []
    for n in r.sample(cknames + [f'p_{cols[0]}_not_null', 
f's_{cols[0]}_not_null'], r.randint(0, 4)):
        pchecks.append((n, r.choice(EXPRS).format(c=r.choice(cols)), flags(r, 
not parted)))
    st = table(r, 'p', cols, pnn, pchecks, partby=cols[0] if parted else None,
               predrop=r.random() < 0.15)
    # child: mostly a faithful copy, with a few deviations
    dev = 0.0 if r.random() < 0.35 else r.choice([0.05, 0.15, 0.4])
    ccols = [c for c in cols if r.random() >= dev * 0.3]
    corder = ccols[:]
    if r.random() < 0.6:
        r.shuffle(corder)
    cnn = {}
    sub = mode == 'subpart'
    for c in ccols:
        if c in pnn:
            if r.random() >= dev:
                cnn[c] = (' NOT NULL', []) if r.random() < 0.5 else 
nn_clause(r, 's', c, not sub, cknames)
        elif r.random() < 0.3:
            cnn[c] = nn_clause(r, 's', c, not sub, cknames)
    cchecks = []
    for n, e, f in pchecks:
        k = r.random()
        if k < dev * 0.5:
            continue                                        # missing in the 
child
        if k < dev:
            e = r.choice(EXPRS).format(c=r.choice(ccols or cols))      # maybe 
another definition
        cf = f if r.random() < 0.6 else flags(r, not sub, 0.1, 0.1, 0.1)
        cchecks.append((n, e, cf))
    for n in r.sample(['q1', 'q2', 'k4', 'k3'], r.randint(0, 2)):
        if n not in [x[0] for x in cchecks]:
            cchecks.append((n, r.choice(EXPRS).format(c=r.choice(ccols or 
cols)), flags(r, not sub)))
    st += table(r, 's', ccols, cnn, cchecks, partby=(ccols or cols)[0] if sub 
else None, order=corder,
                extra=r.randint(0, 2) if r.random() < 0.4 and not parted else 
0, predrop=r.random() < 0.3)
    if sub:
        st.append('CREATE TABLE s1 PARTITION OF s FOR VALUES FROM (0) TO (5)')
    if mode == 'grand':
        st.append('CREATE TABLE g () INHERITS (s)')
    attach = 'ALTER TABLE p ATTACH PARTITION s FOR VALUES FROM (0) TO (10)'
    if mode in ('attach', 'subpart'):
        tgt = [attach]
    elif mode == 'reattach':
        tgt = [attach, 'ALTER TABLE p DETACH PARTITION s', attach]
    elif mode == 'reinherit':
        tgt = ['ALTER TABLE s INHERIT p', 'ALTER TABLE s NO INHERIT p', 'ALTER 
TABLE s INHERIT p']
    elif mode == 'multi':
        c2 = [c for c in cols if r.random() < 0.7] or cols[:1]
        nn2 = {c: nn_clause(r, 'p2', c, True, cknames) for c in c2 if 
r.random() < 0.6}
        ck2 = [(n, e if r.random() < 0.8 else 
r.choice(EXPRS).format(c=r.choice(c2)), flags(r, True))
               for n, e, f in pchecks if r.random() < 0.6]
        st += table(r, 'p2', c2, nn2, ck2)
        tgt = ['ALTER TABLE s INHERIT p', 'ALTER TABLE s INHERIT p2']
    else:
        tgt = ['ALTER TABLE s INHERIT p']
    return mode, st, tgt


def sql(seed):
    mode, st, tgt = case(seed)
    out = [f'\\echo === case {seed} {mode}', 'DROP SCHEMA IF EXISTS o 
CASCADE;', 'CREATE SCHEMA o;']
    if os.environ.get('ORACLE_COMPACT'):
        # with ignore_system_indexes=on the parent's constraints are visited in 
heap order, and
        # which of several violations is reported first depends on it; pruning 
happens at
        # different moments in the two builds, so start every case from a 
compact heap
        out.append('VACUUM FULL pg_constraint;')
    out += [s + ';' for s in st]
    for t in tgt:
        out += [f'\\echo --- target: {t}', t + ';']
    out += ['\\echo --- catalog', DUMP]
    return '\n'.join(out) + '\n'


def run(bindir, work, out, seed0, n, port='54761'):
    work = os.path.abspath(work)
    data, sock = os.path.join(work, f'oracle-data-{port}'), os.path.join(work, 
'sock')
    subprocess.run(['rm', '-rf', data]); os.makedirs(sock, exist_ok=True)
    subprocess.run([f'{bindir}/initdb', '-D', data, '-U', 'postgres', '-A', 
'trust', '--no-sync'],
                   check=True, stdout=subprocess.DEVNULL)
    with open(os.path.join(data, 'postgresql.conf'), 'a') as f:
        f.write("fsync = off\nautovacuum = off\nlisten_addresses = ''\n")
    subprocess.run([f'{bindir}/pg_ctl', '-D', data, '-o', f'-p {port} -k 
{sock}', '-l', data + '.log',
                    '-w', 'start'], check=True, stdout=subprocess.DEVNULL)
    try:
        script = 'SET search_path = o;\nSET client_min_messages = warning;\n' + 
\
                 ''.join(sql(s) for s in range(seed0, seed0 + n)) + '\\echo === 
end\n'
        p = subprocess.run([f'{bindir}/psql', '-X', '-q', '-At', '-h', sock, 
'-p', port, '-U', 'postgres',
                            '-d', 'postgres', '-f', '-'], input=script, 
stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT, text=True)
        open(out, 'w').write(p.stdout)
        done = p.stdout.count('\n=== case ') + p.stdout.startswith('=== case ')
        ok = p.returncode == 0 and p.stdout.rstrip().endswith('=== end') and 
done == n
        # a crash of the backend (assertion) would cut the output short
        print(f'{out}: cases={done}/{n} psql_exit={p.returncode} complete={ok}')
        if not ok:
            sys.exit(1)
    finally:
        subprocess.run([f'{bindir}/pg_ctl', '-D', data, '-m', 'fast', '-w', 
'stop'], stdout=subprocess.DEVNULL)
        subprocess.run(['rm', '-rf', data])


def cases(path):
    cur, d = None, {}
    for line in open(path):
        if line.startswith('=== case '):
            cur = line.split()[2]
            d[cur] = []
        if cur:
            d[cur].append(line)
    return d


def summary(path):
    """Outcome of each target statement, names replaced by "x"; and catalog 
facts reached."""
    import collections
    cls, facts = collections.Counter(), collections.Counter()
    for seed, lines in cases(path).items():
        mode = lines[0].split()[3]
        i = 0
        while i < len(lines):
            if lines[i].startswith('--- target: '):
                kind = ' '.join(w for w in lines[i][12:].split() if w.isupper())
                nxt = lines[i + 1] if i + 1 < len(lines) else ''
                res = re.sub(r'"[^"]*"', '"x"', re.sub(r'^psql:<stdin>:\d+: ', 
'', nxt.strip())) if 'ERROR' in nxt else 'OK'
                cls[(kind, res)] += 1
                facts['mode ' + mode] += 1 if kind else 0
            i += 1
        for l in lines:
            p = l.rstrip('\n').split('|')
            if len(p) == 10 and p[0] == 's' and p[2] in ('c', 'n'):
                facts[f"child {p[2]} coninhcount={p[3]} conislocal={p[4]}"] += 1
    for (kind, res), n in sorted(cls.items(), key=lambda x: (-x[1], x[0])):
        print(f'{n:7}  {kind}: {res}')
    print()
    for k, n in sorted(facts.items()):
        print(f'{n:7}  {k}')


def compare(a, b):
    ca, cb = cases(a), cases(b)
    diff = [s for s in ca if ca[s] != cb.get(s)] + [s for s in cb if s not in 
ca]
    print(f'cases: {len(ca)} vs {len(cb)}; different: {len(diff)}')
    for s in diff[:5]:
        import difflib
        print(f'--- case {s}')
        print(''.join(list(difflib.unified_diff(ca.get(s, []), cb.get(s, []), 
'a', 'b', n=1))[:14]))
    sys.exit(1 if diff or len(ca) != len(cb) else 0)


if __name__ == '__main__':
    a = sys.argv[1:]
    if a and a[0] == 'run':
        run(a[1], a[2], a[3], int(a[4]), int(a[5]), *(a[6:7]))
    elif a and a[0] == 'sql':
        print(sql(int(a[1])), end='')
    elif a and a[0] == 'summary':
        summary(a[1])
    elif a and a[0] == 'compare':
        compare(a[1], a[2])
    else:
        sys.exit(__doc__)
76c602574280670f7ad81a4dc4f015572d25987c0bb9ff6ef5a3f201922d8fa0  
v1-0001-Avoid-quadratic-behavior-in-MergeConstraintsIntoE.patch
curve   round=1 master  N=25    attach_ms=0.625
curve   round=1 master  N=50    attach_ms=1.470
curve   round=1 master  N=100   attach_ms=2.908
curve   round=1 master  N=200   attach_ms=8.587
curve   round=1 master  N=400   attach_ms=23.648
curve   round=1 master  N=800   attach_ms=79.069
curve   round=1 master  N=1600  attach_ms=283.997
curve   round=1 patched N=25    attach_ms=0.611
curve   round=1 patched N=50    attach_ms=1.228
curve   round=1 patched N=100   attach_ms=1.869
curve   round=1 patched N=200   attach_ms=4.219
curve   round=1 patched N=400   attach_ms=8.742
curve   round=1 patched N=800   attach_ms=16.897
curve   round=1 patched N=1600  attach_ms=29.752
curve   round=2 patched N=25    attach_ms=0.768
curve   round=2 patched N=50    attach_ms=1.115
curve   round=2 patched N=100   attach_ms=1.810
curve   round=2 patched N=200   attach_ms=4.178
curve   round=2 patched N=400   attach_ms=7.995
curve   round=2 patched N=800   attach_ms=15.228
curve   round=2 patched N=1600  attach_ms=29.444
curve   round=2 master  N=25    attach_ms=0.593
curve   round=2 master  N=50    attach_ms=1.383
curve   round=2 master  N=100   attach_ms=2.866
curve   round=2 master  N=200   attach_ms=8.179
curve   round=2 master  N=400   attach_ms=23.270
curve   round=2 master  N=800   attach_ms=77.583
curve   round=2 master  N=1600  attach_ms=273.614
curve   round=3 master  N=25    attach_ms=0.694
curve   round=3 master  N=50    attach_ms=1.398
curve   round=3 master  N=100   attach_ms=2.863
curve   round=3 master  N=200   attach_ms=8.283
curve   round=3 master  N=400   attach_ms=23.075
curve   round=3 master  N=800   attach_ms=78.680
curve   round=3 master  N=1600  attach_ms=282.724
curve   round=3 patched N=25    attach_ms=0.556
curve   round=3 patched N=50    attach_ms=1.163
curve   round=3 patched N=100   attach_ms=1.885
curve   round=3 patched N=200   attach_ms=4.622
curve   round=3 patched N=400   attach_ms=7.239
curve   round=3 patched N=800   attach_ms=15.512
curve   round=3 patched N=1600  attach_ms=29.834
curve   round=4 patched N=25    attach_ms=0.585
curve   round=4 patched N=50    attach_ms=1.145
curve   round=4 patched N=100   attach_ms=1.828
curve   round=4 patched N=200   attach_ms=4.155
curve   round=4 patched N=400   attach_ms=7.410
curve   round=4 patched N=800   attach_ms=15.449
curve   round=4 patched N=1600  attach_ms=29.563
curve   round=4 master  N=25    attach_ms=0.659
curve   round=4 master  N=50    attach_ms=1.442
curve   round=4 master  N=100   attach_ms=3.048
curve   round=4 master  N=200   attach_ms=8.516
curve   round=4 master  N=400   attach_ms=24.271
curve   round=4 master  N=800   attach_ms=78.243
curve   round=4 master  N=1600  attach_ms=276.977
curve   round=5 master  N=25    attach_ms=0.596
curve   round=5 master  N=50    attach_ms=1.459
curve   round=5 master  N=100   attach_ms=2.874
curve   round=5 master  N=200   attach_ms=8.487
curve   round=5 master  N=400   attach_ms=23.194
curve   round=5 master  N=800   attach_ms=77.320
curve   round=5 master  N=1600  attach_ms=279.586
curve   round=5 patched N=25    attach_ms=0.555
curve   round=5 patched N=50    attach_ms=1.238
curve   round=5 patched N=100   attach_ms=1.829
curve   round=5 patched N=200   attach_ms=4.223
curve   round=5 patched N=400   attach_ms=7.252
curve   round=5 patched N=800   attach_ms=15.416
curve   round=5 patched N=1600  attach_ms=29.559
curve   round=6 patched N=25    attach_ms=0.554
curve   round=6 patched N=50    attach_ms=1.120
curve   round=6 patched N=100   attach_ms=1.845
curve   round=6 patched N=200   attach_ms=4.310
curve   round=6 patched N=400   attach_ms=7.384
curve   round=6 patched N=800   attach_ms=15.661
curve   round=6 patched N=1600  attach_ms=32.322
curve   round=6 master  N=25    attach_ms=0.621
curve   round=6 master  N=50    attach_ms=1.659
curve   round=6 master  N=100   attach_ms=3.303
curve   round=6 master  N=200   attach_ms=9.252
curve   round=6 master  N=400   attach_ms=23.276
curve   round=6 master  N=800   attach_ms=76.845
curve   round=6 master  N=1600  attach_ms=274.674
curve   round=7 master  N=25    attach_ms=0.602
curve   round=7 master  N=50    attach_ms=1.557
curve   round=7 master  N=100   attach_ms=2.864
curve   round=7 master  N=200   attach_ms=8.400
curve   round=7 master  N=400   attach_ms=23.639
curve   round=7 master  N=800   attach_ms=76.936
curve   round=7 master  N=1600  attach_ms=274.353
curve   round=7 patched N=25    attach_ms=0.617
curve   round=7 patched N=50    attach_ms=1.126
curve   round=7 patched N=100   attach_ms=1.833
curve   round=7 patched N=200   attach_ms=4.207
curve   round=7 patched N=400   attach_ms=7.223
curve   round=7 patched N=800   attach_ms=15.376
curve   round=7 patched N=1600  attach_ms=29.981
curve   round=8 patched N=25    attach_ms=0.539
curve   round=8 patched N=50    attach_ms=1.123
curve   round=8 patched N=100   attach_ms=1.870
curve   round=8 patched N=200   attach_ms=4.232
curve   round=8 patched N=400   attach_ms=7.457
curve   round=8 patched N=800   attach_ms=15.181
curve   round=8 patched N=1600  attach_ms=29.045
curve   round=8 master  N=25    attach_ms=0.620
curve   round=8 master  N=50    attach_ms=1.444
curve   round=8 master  N=100   attach_ms=2.955
curve   round=8 master  N=200   attach_ms=15.275
curve   round=8 master  N=400   attach_ms=41.470
curve   round=8 master  N=800   attach_ms=107.900
curve   round=8 master  N=1600  attach_ms=283.627
curve   round=9 master  N=25    attach_ms=1.078
curve   round=9 master  N=50    attach_ms=2.622
curve   round=9 master  N=100   attach_ms=4.857
curve   round=9 master  N=200   attach_ms=15.691
curve   round=9 master  N=400   attach_ms=43.590
curve   round=9 master  N=800   attach_ms=148.338
curve   round=9 master  N=1600  attach_ms=542.663
curve   round=9 patched N=25    attach_ms=0.678
curve   round=9 patched N=50    attach_ms=1.694
curve   round=9 patched N=100   attach_ms=1.981
curve   round=9 patched N=200   attach_ms=5.472
curve   round=9 patched N=400   attach_ms=14.399
curve   round=9 patched N=800   attach_ms=23.621
curve   round=9 patched N=1600  attach_ms=37.963
curve   round=10        patched N=25    attach_ms=0.571
curve   round=10        patched N=50    attach_ms=1.145
curve   round=10        patched N=100   attach_ms=1.893
curve   round=10        patched N=200   attach_ms=4.383
curve   round=10        patched N=400   attach_ms=7.595
curve   round=10        patched N=800   attach_ms=16.055
curve   round=10        patched N=1600  attach_ms=29.718
curve   round=10        master  N=25    attach_ms=0.629
curve   round=10        master  N=50    attach_ms=1.470
curve   round=10        master  N=100   attach_ms=2.958
curve   round=10        master  N=200   attach_ms=8.289
curve   round=10        master  N=400   attach_ms=23.246
curve   round=10        master  N=800   attach_ms=77.666
curve   round=10        master  N=1600  attach_ms=274.615
curve   round=11        master  N=25    attach_ms=0.587
curve   round=11        master  N=50    attach_ms=1.541
curve   round=11        master  N=100   attach_ms=2.919
curve   round=11        master  N=200   attach_ms=8.231
curve   round=11        master  N=400   attach_ms=23.304
curve   round=11        master  N=800   attach_ms=79.142
curve   round=11        master  N=1600  attach_ms=276.031
curve   round=11        patched N=25    attach_ms=0.719
curve   round=11        patched N=50    attach_ms=1.148
curve   round=11        patched N=100   attach_ms=1.866
curve   round=11        patched N=200   attach_ms=4.399
curve   round=11        patched N=400   attach_ms=7.755
curve   round=11        patched N=800   attach_ms=15.828
curve   round=11        patched N=1600  attach_ms=29.840
curve   round=12        patched N=25    attach_ms=0.556
curve   round=12        patched N=50    attach_ms=1.181
curve   round=12        patched N=100   attach_ms=1.941
curve   round=12        patched N=200   attach_ms=4.715
curve   round=12        patched N=400   attach_ms=8.484
curve   round=12        patched N=800   attach_ms=17.541
curve   round=12        patched N=1600  attach_ms=33.248
curve   round=12        master  N=25    attach_ms=0.622
curve   round=12        master  N=50    attach_ms=1.473
curve   round=12        master  N=100   attach_ms=2.864
curve   round=12        master  N=200   attach_ms=8.494
curve   round=12        master  N=400   attach_ms=23.742
curve   round=12        master  N=800   attach_ms=82.571
curve   round=12        master  N=1600  attach_ms=289.146
curve   round=13        master  N=25    attach_ms=0.620
curve   round=13        master  N=50    attach_ms=1.423
curve   round=13        master  N=100   attach_ms=2.841
curve   round=13        master  N=200   attach_ms=8.407
curve   round=13        master  N=400   attach_ms=23.219
curve   round=13        master  N=800   attach_ms=77.937
curve   round=13        master  N=1600  attach_ms=276.214
curve   round=13        patched N=25    attach_ms=0.579
curve   round=13        patched N=50    attach_ms=1.148
curve   round=13        patched N=100   attach_ms=1.909
curve   round=13        patched N=200   attach_ms=4.268
curve   round=13        patched N=400   attach_ms=7.242
curve   round=13        patched N=800   attach_ms=15.465
curve   round=13        patched N=1600  attach_ms=29.490
curve   round=14        patched N=25    attach_ms=0.549
curve   round=14        patched N=50    attach_ms=1.151
curve   round=14        patched N=100   attach_ms=1.850
curve   round=14        patched N=200   attach_ms=4.339
curve   round=14        patched N=400   attach_ms=7.458
curve   round=14        patched N=800   attach_ms=16.600
curve   round=14        patched N=1600  attach_ms=32.109
curve   round=14        master  N=25    attach_ms=0.672
curve   round=14        master  N=50    attach_ms=1.424
curve   round=14        master  N=100   attach_ms=2.929
curve   round=14        master  N=200   attach_ms=8.886
curve   round=14        master  N=400   attach_ms=24.247
curve   round=14        master  N=800   attach_ms=79.515
curve   round=14        master  N=1600  attach_ms=276.098
curve   round=15        master  N=25    attach_ms=0.623
curve   round=15        master  N=50    attach_ms=1.386
curve   round=15        master  N=100   attach_ms=2.837
curve   round=15        master  N=200   attach_ms=8.259
curve   round=15        master  N=400   attach_ms=23.320
curve   round=15        master  N=800   attach_ms=76.922
curve   round=15        master  N=1600  attach_ms=277.283
curve   round=15        patched N=25    attach_ms=0.582
curve   round=15        patched N=50    attach_ms=1.165
curve   round=15        patched N=100   attach_ms=1.806
curve   round=15        patched N=200   attach_ms=4.175
curve   round=15        patched N=400   attach_ms=7.340
curve   round=15        patched N=800   attach_ms=15.331
curve   round=15        patched N=1600  attach_ms=29.866
curve   round=16        patched N=25    attach_ms=0.558
curve   round=16        patched N=50    attach_ms=1.140
curve   round=16        patched N=100   attach_ms=1.844
curve   round=16        patched N=200   attach_ms=4.196
curve   round=16        patched N=400   attach_ms=7.275
curve   round=16        patched N=800   attach_ms=16.237
curve   round=16        patched N=1600  attach_ms=31.014
curve   round=16        master  N=25    attach_ms=0.579
curve   round=16        master  N=50    attach_ms=1.390
curve   round=16        master  N=100   attach_ms=2.997
curve   round=16        master  N=200   attach_ms=8.517
curve   round=16        master  N=400   attach_ms=23.354
curve   round=16        master  N=800   attach_ms=77.806
curve   round=16        master  N=1600  attach_ms=276.174
curve   round=17        master  N=25    attach_ms=0.619
curve   round=17        master  N=50    attach_ms=1.433
curve   round=17        master  N=100   attach_ms=2.892
curve   round=17        master  N=200   attach_ms=8.362
curve   round=17        master  N=400   attach_ms=23.366
curve   round=17        master  N=800   attach_ms=77.488
curve   round=17        master  N=1600  attach_ms=275.319
curve   round=17        patched N=25    attach_ms=0.545
curve   round=17        patched N=50    attach_ms=1.215
curve   round=17        patched N=100   attach_ms=1.843
curve   round=17        patched N=200   attach_ms=4.235
curve   round=17        patched N=400   attach_ms=7.281
curve   round=17        patched N=800   attach_ms=15.320
curve   round=17        patched N=1600  attach_ms=29.606
curve   round=18        patched N=25    attach_ms=0.542
curve   round=18        patched N=50    attach_ms=1.186
curve   round=18        patched N=100   attach_ms=1.894
curve   round=18        patched N=200   attach_ms=4.161
curve   round=18        patched N=400   attach_ms=7.409
curve   round=18        patched N=800   attach_ms=15.621
curve   round=18        patched N=1600  attach_ms=29.810
curve   round=18        master  N=25    attach_ms=0.608
curve   round=18        master  N=50    attach_ms=1.452
curve   round=18        master  N=100   attach_ms=3.049
curve   round=18        master  N=200   attach_ms=8.680
curve   round=18        master  N=400   attach_ms=24.886
curve   round=18        master  N=800   attach_ms=80.584
curve   round=18        master  N=1600  attach_ms=293.561
curve   round=19        master  N=25    attach_ms=0.610
curve   round=19        master  N=50    attach_ms=1.442
curve   round=19        master  N=100   attach_ms=2.877
curve   round=19        master  N=200   attach_ms=8.914
curve   round=19        master  N=400   attach_ms=24.376
curve   round=19        master  N=800   attach_ms=77.121
curve   round=19        master  N=1600  attach_ms=279.630
curve   round=19        patched N=25    attach_ms=0.559
curve   round=19        patched N=50    attach_ms=1.141
curve   round=19        patched N=100   attach_ms=1.909
curve   round=19        patched N=200   attach_ms=4.392
curve   round=19        patched N=400   attach_ms=7.682
curve   round=19        patched N=800   attach_ms=15.585
curve   round=19        patched N=1600  attach_ms=31.871
curve   round=20        patched N=25    attach_ms=0.584
curve   round=20        patched N=50    attach_ms=1.247
curve   round=20        patched N=100   attach_ms=1.955
curve   round=20        patched N=200   attach_ms=4.561
curve   round=20        patched N=400   attach_ms=8.023
curve   round=20        patched N=800   attach_ms=16.196
curve   round=20        patched N=1600  attach_ms=32.821
curve   round=20        master  N=25    attach_ms=0.592
curve   round=20        master  N=50    attach_ms=1.416
curve   round=20        master  N=100   attach_ms=2.907
curve   round=20        master  N=200   attach_ms=8.381
curve   round=20        master  N=400   attach_ms=24.839
curve   round=20        master  N=800   attach_ms=77.576
curve   round=20        master  N=1600  attach_ms=276.352
CURVE-DONE
round   build   instructions_u  restore_instructions_u_approx   restore_s       
upgrade_s
1       m       531061135279    471404228144    34.043  43.371
1       mc      529887706524    469887450510    33.922  43.469
1       fk      522656651963    461715176058    33.488  43.620
1       both    522480871192    462942547047    31.890  41.323
2       mc      530232937017    473067965114    32.409  41.985
2       fk      522517787574    463335003512    33.570  43.228
2       both    521842019922    462684317464    33.350  43.157
2       m       530460570968    473096936669    33.616  43.524
3       fk      522933965890    463851057075    33.567  43.480
3       both    522492497211    462488952474    32.911  42.856
3       m       530307127080    471916187063    33.986  44.140
3       mc      530192275376    469160444094    34.258  44.156

Reply via email to