Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fxEXE-0006yb-G3 for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Sep 2018 16:50:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fxEXC-0008St-6l for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Sep 2018 16:50:34 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fxEXB-0008Sm-Lq for pgsql-hackers@lists.postgresql.org; Tue, 04 Sep 2018 16:50:34 +0000 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fxEX7-0000wz-Nu for pgsql-hackers@postgresql.org; Tue, 04 Sep 2018 16:50:32 +0000 Received: by mail-qt0-x242.google.com with SMTP id n6-v6so4754629qtl.4 for ; Tue, 04 Sep 2018 09:50:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=4XgasrtQa/Q5YUAtCZh5H/Q8oWoRnp4Ddav1tMsA67M=; b=DyL0QYgPSDhLPALAqFAcQwZEMZyMWRkhBDb8cEeIvBqbaGJ9hZGqrCRKTpsO+o/j3w NdsoYpmokRfrwU6SYaNICpNAFRSt/+KnTBzS22dVO8Jp3y6sueMeF7OYkrwlaUqHxJyE FzQRvHxMHd+8T9obRkEgnnw1LmjjfiOylwzdc4wG+hoJ0Y/AnSpJHWBFbB1XYCJ9pdiL ftQgKdGY9y8LUZT0o31q02+5kF5xJRlgtnsZCpx6h5Rf0tfT+MAfGBfYNrDf+Q9iHhQu bhiw5qb2FBwyG7BHgJ9EKKMkQ8odC/EopUw0EgB8U+4nyDQJwqn26ybR5P9LMCcgCR5Y AwkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=4XgasrtQa/Q5YUAtCZh5H/Q8oWoRnp4Ddav1tMsA67M=; b=PHFTz/VL5GM4Gk2gVJgFfHfKB5/zQ3s5PDji+HKkX3z1eg520n16e7JzuVpgwH+gZI gPpVrsNu7oCxN6gPjhUYaX8mBOn+dkpVB0McJvYW70FaZtckHVpTytBtEniS07CqK+PS bj45dDbU9ogEjWJIF5EEVdLcqdzzT+CHGBMcEDahnPkVnpOKes5G03U5YBrW8Tce3MIU axua8yRyZ89BtgkeY81L1kMG/woHYpoldfnQvRP8aDVkcqAvuwtVNeiKUyi1X6i6ovjb s4FNKoaJ3fgdZrn3AfHGU0rHac6Wv8pkRb+JGhEpxJK1rHFAOh00tv3cLH02GDlxGH91 mb+w== X-Gm-Message-State: APzg51AnHv+wAlf/8iEdvsJ2GeI/JOokKRK6ZObbbdqoLVImo8R3Dpqw KqBM9WDgP2MAwUrpvm53gpUZR6TpU4M= X-Google-Smtp-Source: ANB0VdYF132kHNrQ/p3h/TeW4ZyQDaboYlj04ZwnibeijMUuAO6CqpwjVk+pXV2Itn591myMNvmNGQ== X-Received: by 2002:a0c:b542:: with SMTP id w2-v6mr30099347qvd.156.1536079828763; Tue, 04 Sep 2018 09:50:28 -0700 (PDT) Received: from alvin.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id c2-v6sm11725334qkc.20.2018.09.04.09.50.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Sep 2018 09:50:27 -0700 (PDT) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 88D9096A; Tue, 4 Sep 2018 13:50:25 -0300 (-03) Date: Tue, 4 Sep 2018 13:50:25 -0300 From: Alvaro Herrera To: Amit Langote Cc: Michael Paquier , Pg Hackers Subject: Re: pointless check in RelationBuildPartitionDesc Message-ID: <20180904165025.zhby7ahrbkp7jf5l@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="chw3rqes4lwo6ohf" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180904125128.ntliwrygsylaar4b@alvherre.pgsql> User-Agent: NeoMutt/20170306-137-4415bd-dirty (1.8.0) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --chw3rqes4lwo6ohf Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit Proposed patch. Checking isnull in a elog(ERROR) is important, because the column is not marked NOT NULL. This is not true for other columns where we simply do Assert(!isnull). -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --chw3rqes4lwo6ohf Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="ispartition.patch" Content-Transfer-Encoding: quoted-printable commit dc5f9933595c95471898e506e004a1799ea4eae5=1B[m Author: Alvaro Herrera AuthorDate: Tue Sep 4 13:24:25 2018 -0300 CommitDate: Tue Sep 4 13:27:30 2018 -0300 fix relpartbound accesses diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablec= mds.c index f46af41b56..ffdd14b819 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -773,9 +773,6 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid owne= rId, InvalidOid, typaddress); =20 - /* Store inheritance information for new rel. */ - StoreCatalogInheritance(relationId, inheritOids, stmt->partbound !=3D NUL= L); - /* * We must bump the command counter to make the newly-created relation * tuple visible for opening. @@ -869,6 +866,9 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid owne= rId, heap_close(parent, NoLock); } =20 + /* Store inheritance information for new rel. */ + StoreCatalogInheritance(relationId, inheritOids, stmt->partbound !=3D NUL= L); + /* * Process the partitioning specification (if any) and store the partition * key information into the catalog. @@ -14705,7 +14705,9 @@ ATExecDetachPartition(Relation rel, RangeVar *name) =20 (void) SysCacheGetAttr(RELOID, tuple, Anum_pg_class_relpartbound, &isnull); - Assert(!isnull); + if (isnull) + elog(ERROR, "null relpartbound for relation %u", + RelationGetRelid(partRel)); =20 /* Clear relpartbound and reset relispartition */ memset(new_val, 0, sizeof(new_val)); diff --git a/src/backend/partitioning/partbounds.c b/src/backend/partitioni= ng/partbounds.c index 9015a05d32..4ed9920618 100644 --- a/src/backend/partitioning/partbounds.c +++ b/src/backend/partitioning/partbounds.c @@ -1641,8 +1641,9 @@ get_qual_for_range(Relation parent, PartitionBoundSpe= c *spec, datum =3D SysCacheGetAttr(RELOID, tuple, Anum_pg_class_relpartbound, &isnull); + if (isnull) + elog(ERROR, "null relpartbound for relation %u", inhrelid); =20 - Assert(!isnull); bspec =3D (PartitionBoundSpec *) stringToNode(TextDatumGetCString(datum)); if (!IsA(bspec, PartitionBoundSpec)) diff --git a/src/backend/utils/cache/partcache.c b/src/backend/utils/cache/= partcache.c index 115a9fe78f..2fc876b7d8 100644 --- a/src/backend/utils/cache/partcache.c +++ b/src/backend/utils/cache/partcache.c @@ -302,23 +302,11 @@ RelationBuildPartitionDesc(Relation rel) if (!HeapTupleIsValid(tuple)) elog(ERROR, "cache lookup failed for relation %u", inhrelid); =20 - /* - * It is possible that the pg_class tuple of a partition has not been - * updated yet to set its relpartbound field. The only case where - * this happens is when we open the parent relation to check using its - * partition descriptor that a new partition's bound does not overlap - * some existing partition. - */ - if (!((Form_pg_class) GETSTRUCT(tuple))->relispartition) - { - ReleaseSysCache(tuple); - continue; - } - datum =3D SysCacheGetAttr(RELOID, tuple, Anum_pg_class_relpartbound, &isnull); - Assert(!isnull); + if (isnull) + elog(ERROR, "null relpartbound for partition %u" inhrelid); boundspec =3D (Node *) stringToNode(TextDatumGetCString(datum)); =20 /* @@ -883,9 +871,8 @@ generate_partition_qual(Relation rel) boundDatum =3D SysCacheGetAttr(RELOID, tuple, Anum_pg_class_relpartbound, &isnull); - if (isnull) /* should not happen */ - elog(ERROR, "relation \"%s\" has relpartbound =3D null", - RelationGetRelationName(rel)); + if (isnull) + elog(ERROR, "null relpartbound for relation %u", RelationGetRelid(rel)); bound =3D castNode(PartitionBoundSpec, stringToNode(TextDatumGetCString(boundDatum))); ReleaseSysCache(tuple); --chw3rqes4lwo6ohf--