Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sFJHt-0014jZ-Iu for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Jun 2024 20:00:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sFJHr-003dcx-IB for pgsql-hackers@arkaria.postgresql.org; Thu, 06 Jun 2024 20:00:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sFJHr-003dcp-5W for pgsql-hackers@lists.postgresql.org; Thu, 06 Jun 2024 20:00:40 +0000 Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sFJHp-000LP1-3X for pgsql-hackers@lists.postgresql.org; Thu, 06 Jun 2024 20:00:39 +0000 Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-a6265d3ba8fso138503966b.0 for ; Thu, 06 Jun 2024 13:00:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717704035; x=1718308835; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=q8eh09qeeMCycYJj3YVd/MmtH1zWgbJDbFarg7iZwCY=; b=WnEdIHjTa4xjRTiEuXt1OBxMhOP4RZ8AR1aU8VDwKodYco92As96EZvyEywsYJlXKA WrpEK+7i21E8LYNyU1K28nBDwwzCMBk0XRFC+XuByer1tEZ8QZsCWPY2JabhvDo9JzHc YRJWqBWH8NMnw7LBxqCSTQz+wPPKKkRBguXWjNbPAIX1oKuu6t1ZfJMcTZiN4fo5DZlg /myvVAkhbPKTs4FgB1ZZ4VItw8JXZrZbgi2t8NEi3e+zsQHK7pTHBYIiQJLppF+heKsY JMSb0yGCfmGag3tLu1+rC3Qb2r9Z10o8j6kTqaPFQL2X1Ten4eZFz0ZOpyhiNv225dkH +Aww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717704035; x=1718308835; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=q8eh09qeeMCycYJj3YVd/MmtH1zWgbJDbFarg7iZwCY=; b=e/fDMl+4vrFO5OXzuB1xw20SUA+DGmum2Y/2e7g5VxZWPwdVD+9nN2/aAn6+xbItou wk7kS0QoDAhLkMFauL/nVmsDKW2btM+cKDt2n0QAi/3gwTa4f7lyhOVgBXCwfI9Vm4C+ Hx3ywARY0T8cU0psLKUwSJ81skZo2j/ZUGlpWwjykir9+xJqVghIv2FKeIODlpjPsfYX QEqypltj9putfRHhte/2DvYcZlpTkAuPXnZYAO/wlGgtglxcEJAdSe77KMVGY51laW+q AlQizadHeMuoR5IfwWTI4qL2MTNZ7+bmsOGyhW0/j4/+FfsBScwSMkGm10kFVp//FsnG ukMw== X-Forwarded-Encrypted: i=1; AJvYcCUVACRcZlF+CHV8pPUWJtJnuA4AjMAGGgf8sng1XfkrOKYRi4qablPTh/qpr8nI4QhzreKVBV4M1+R+FuCxtsVaX6wkmHwpOjODZ6WxON9OsNkZ X-Gm-Message-State: AOJu0Ywi8iwGKsryaYrhMZsvm5SJrbZL18p4N2a75x26rVsmw70VDB7w atktAsIbdlYJDamIdPtg8yuBWvIQp25jN7a0Ln+uf3xv5B1v6L1ITGlw5mnuYbIOD+XTxpUHCb2 l+JpRL5hwHFBffQkTIueJ8yAfzwA= X-Google-Smtp-Source: AGHT+IGuMsYRB1M03sCuq4I43YJTknldOa4tp4Bfk/7NuvrN3YvK/MctwlbSoi69lHNBoezY0UtQYwKDcdCyE3MhGoQ= X-Received: by 2002:a17:906:52d1:b0:a59:9c58:763a with SMTP id a640c23a62f3a-a6cd7891eb4mr39925366b.46.1717704035208; Thu, 06 Jun 2024 13:00:35 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Robert Haas Date: Thu, 6 Jun 2024 16:00:23 -0400 Message-ID: Subject: Re: Avoid orphaned objects dependencies, take 3 To: Bertrand Drouvot Cc: Michael Paquier , Alexander Lakhin , pgsql-hackers@lists.postgresql.org, Tom Lane Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Jun 6, 2024 at 1:56=E2=80=AFAM Bertrand Drouvot wrote: > v9 is more invasive (as it changes code in much more places) than v8 but = it is > easier to follow (as it is now clear where the new lock is acquired). Hmm, this definitely isn't what I had in mind. Possibly that's a sign that what I had in mind was dumb, but for sure it's not what I imagined. What I thought you were going to do was add calls like LockDatabaseObject(NamespaceRelationId, schemaid, 0, AccessShareLock) in various places, or perhaps LockRelationOid(reloid, AccessShareLock), or whatever the case may be. Here you've got stuff like this: - record_object_address_dependencies(&conobject, addrs_auto, - DEPENDENCY_AUTO); + lock_record_object_address_dependencies(&conobject, addrs_auto, + DEPENDENCY_AUTO); ...which to me looks like the locking is still pushed down inside the dependency code. And you also have stuff like this: ObjectAddressSet(referenced, RelationRelationId, childTableId); + depLockAndCheckObject(&referenced); recordDependencyOn(&depender, &referenced, DEPENDENCY_PARTITION_SEC); But in depLockAndCheckObject you have: + if (object->classId =3D=3D RelationRelationId || object->classId =3D=3D AuthMemRelationId) + return; That doesn't seem right, because then it seems like the call isn't doing anything, but there isn't really any reason for it to not be doing anything. If we're dropping a dependency on a table, then it seems like we need to have a lock on that table. Presumably the reason why we don't end up with dangling dependencies in such cases now is because we're careful about doing LockRelation() in the right places, but we're not similarly careful about other operations e.g. ConstraintSetParentConstraint is called by DefineIndex which calls table_open(childRelId, ...) first, but there's no logic in DefineIndex to lock the constraint. Thoughts? --=20 Robert Haas EDB: http://www.enterprisedb.com