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 1sFVAO-002uAK-8j for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Jun 2024 08:41:45 +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 1sFVAM-009zgD-No for pgsql-hackers@arkaria.postgresql.org; Fri, 07 Jun 2024 08:41:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sFVAM-009zg3-Ag for pgsql-hackers@lists.postgresql.org; Fri, 07 Jun 2024 08:41:43 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sFVAK-0008Ed-Bk for pgsql-hackers@lists.postgresql.org; Fri, 07 Jun 2024 08:41:41 +0000 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-35f090093d8so208890f8f.0 for ; Fri, 07 Jun 2024 01:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717749699; x=1718354499; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=cpMWOjdEn+JfJ8XrUri6mwE+Y/43zhBBbCm7QVVSU58=; b=K+tL5VPAOEr8YyS9J1JJO6KKCvfTwtnXI3e5p438F6Vqjf0Q7HTJS0ly5d138oVcL7 kPvyxioxqSV2kQq7bypkQpqJr64XTnk0rpr/mpkraBTGHn5/HyBF8E8yuvm9rqa4pv8/ Gnl6QhU33U1zRh6mVIOfgTWAxBZmZv2VvnyMSwjn94GJpJREZYPJxvfCZHQpqO/pQiYO 9nZ0aZoECkGu3gk6R9/hJlh6HkdZA0q6wwgWBkJoVZOBryWOQhUZRjuBbE71klTohKrn g+nf2AoQ06GdWjkLfWPJpBrhNPyHDvw8bN7KKuxlBLwkudD4CzfJchQDoGAqEhmsgu28 1tSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717749699; x=1718354499; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cpMWOjdEn+JfJ8XrUri6mwE+Y/43zhBBbCm7QVVSU58=; b=ts+8LhgeUCE1hMGACn6z/KXJNwszS+TFfyFKOOE7w0Y4Ol/uhTvB+8e7E1Ug11Opsi TKsnbyvYmUNlJdHdn99XraA8gpRNlNkzIBkQ5+bE8/UWXF1VYS//7fjWxfyKQ3vm36y2 3uYIR65EwC0MG0uKXYSEp1xRW5EvzphjMuasqKqF5e4eoJmZa68pdPIYp0bIOzaXGxlv AVUAWUv6XgHzf5iYVrNnuI0aVlCT3nGiVb95svN5uMZMQELXrGUPaftT1SiwVtlaH/5a c/aFK5rylmp68OV1ej0FADJjrRJWHU0QyPdtKZcKSsJQwT9hS3a4/Q+Cj0ruNZyBKCzo S+Sg== X-Forwarded-Encrypted: i=1; AJvYcCXWIL7Qe8FVF0+LGE7r4jymi3WOMIsIyx212X3bkmfpJyW/2V251T1Zheo5/nMctjs85yhvPXSyTpQ24kONyiPVWDTFl2MKoIJxxmOgovV5QwUZ X-Gm-Message-State: AOJu0YyGmUTLNJWxJOaYEAdkAF7WOviGGl7/13SyymuVutAGRJaOPvz+ 7qcbiyliKZHhFvK0La3s1lDjU+1NGm7VAsQyISgzuVPNC2ABadcK X-Google-Smtp-Source: AGHT+IFKcdj8AyGcarsAmpTLYu3Vk+CVxs1t2Y8MOjdyHvrFWP8jg1iSiadYEEFHgI0OJd/RiRcT8A== X-Received: by 2002:a5d:56c1:0:b0:35e:7dd8:1583 with SMTP id ffacd0b85a97d-35efed3f376mr1266224f8f.24.1717749698528; Fri, 07 Jun 2024 01:41:38 -0700 (PDT) Received: from ip-10-97-1-34.eu-west-3.compute.internal (ec2-15-236-134-5.eu-west-3.compute.amazonaws.com. [15.236.134.5]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35ef5fd1b56sm3478707f8f.112.2024.06.07.01.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 01:41:38 -0700 (PDT) Date: Fri, 7 Jun 2024 08:41:36 +0000 From: Bertrand Drouvot To: Robert Haas Cc: Michael Paquier , Alexander Lakhin , pgsql-hackers@lists.postgresql.org, Tom Lane Subject: Re: Avoid orphaned objects dependencies, take 3 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Thu, Jun 06, 2024 at 04:00:23PM -0400, Robert Haas wrote: > On Thu, Jun 6, 2024 at 1:56 AM 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. I see what you’re saying, doing things like: LockDatabaseObject(TypeRelationId, returnType, 0, AccessShareLock); in ProcedureCreate() for example. > 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. Yes but it’s now located in places where, I think, it’s easier to understand what’s going on (as compare to v8), except maybe for: recordDependencyOnExpr() makeOperatorDependencies() GenerateTypeDependencies() makeParserDependencies() makeDictionaryDependencies() makeTSTemplateDependencies() makeConfigurationDependencies() but probably for: heap_create_with_catalog() StorePartitionKey() index_create() AggregateCreate() CastCreate() CreateConstraintEntry() ProcedureCreate() RangeCreate() InsertExtensionTuple() CreateTransform() CreateProceduralLanguage() The reasons I keep it linked to the dependency code are: - To ensure we don’t miss anything (well, with the new Assert in place that’s probably a tangential argument) - It’s not only about locking the object: it’s also about 1) verifying the object is pinned, 2) checking it still exists and 3) provide a description in the error message if we can (in case the object does not exist anymore). Relying on an already build object (in the dependency code) avoid to 1) define the object(s) one more time or 2) create new functions that would do the same as isObjectPinned() and getObjectDescription() with a different set of arguments. That may sounds like weak arguments but it has been my reasoning. Do you still find the code hard to maintain with v9? > > 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 == RelationRelationId || object->classId == > 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, Yeah, that's what I think: we're already careful when we deal with relations. > 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. table_open(childRelId, ...) would lock any "ALTER TABLE DROP CONSTRAINT" already. Not sure I understand your concern here. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com