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 1rztOx-007hhC-10 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Apr 2024 07:20:15 +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 1rztOv-0040yz-EK for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Apr 2024 07:20:13 +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 1rztOv-0040yr-09 for pgsql-hackers@lists.postgresql.org; Thu, 25 Apr 2024 07:20:13 +0000 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rztOs-004Y0h-8H for pgsql-hackers@lists.postgresql.org; Thu, 25 Apr 2024 07:20:11 +0000 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-2de233961caso5972791fa.3 for ; Thu, 25 Apr 2024 00:20:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714029607; x=1714634407; 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=NwSN4+DlzCfoa2YCiw0QVXFUzYiitxQbu6wcGvyEaF4=; b=KY8o3S30MHYQsfXXmZxwKhP5zWH6WjN89OtXpNRq1W9hBodgpYXfjALLVN3RLbf2Mv aBFdXZ1HXzk3YzYGcJJtH5vPUjRTuqNyAniibxQBPuiKaNu4tOUjK0lklN1/swhhb4gR JN4wj5TWVDiX+ZH/6EpfUg2rNkQihD82yM6PCxU4frD7X4pOs7JxhKpNVKqOZ7BhJcCh bctxPiZvE+AWq6oKlCZgEb7Lklcio/eX8PC5xEjofGq125uBqqLb49lY5aNvEEx0KVrG tw5ZbBV2Bgh/oboVMokxuWluzMBPfWOcadJGjFr5Rr9TlgP+Zu/cPJyZlImdg7FBDsm0 GfQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714029607; x=1714634407; 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=NwSN4+DlzCfoa2YCiw0QVXFUzYiitxQbu6wcGvyEaF4=; b=C00vyVARXoNfmTan0QGfIXx1FZg+8BeagkPOAhOY0UG+EFcHzfL4FOXGn1fJb1P0AG bLGdMn55VHulJISpBOYSV10Zbm1642WhRur9H7KJzTcXgpyNk5K0kWxrqY4NWbHVcho0 NA4vNzAM/pIEAZOO3iwUNlNlN3fRAMEI0Pg8n01mXVgVlo1trwmgUZj4jfkG3LlgFbzG SyKXmPietQqsWUP82n6/frLN8X9v4k/ynq6Nmj1prJ3Bo7kQSbCc2FhFX2NCPLpan83X JPH59QZ6gjgrd11/np5WPc9pp6SSVV2kIuEW9QyPeCQ0TZaLXZP86nmGGVHypC6CKUKF 8t6w== X-Gm-Message-State: AOJu0YwHEqAVy9yU7R9RjFMOnxIsnrLSanrl389Xe4pFYxUCga4LJr7s ZS5m3fwnA0u7QtmgzXOy+g66pKH7l7fboWWySMfzwumx4zrhzEr5 X-Google-Smtp-Source: AGHT+IFDRuhjeZJpWjlNF+szJiXiaOIMHdMOjfZvxRQHsyuz9krnIPDXbcsjdZB5P5pELvX6awu1Ow== X-Received: by 2002:a2e:9506:0:b0:2dd:66ea:5fbd with SMTP id f6-20020a2e9506000000b002dd66ea5fbdmr4017369ljh.44.1714029606728; Thu, 25 Apr 2024 00:20:06 -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 n40-20020a05600c502800b0041b4c293f75sm987256wmr.13.2024.04.25.00.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 00:20:06 -0700 (PDT) Date: Thu, 25 Apr 2024 07:20:05 +0000 From: Bertrand Drouvot To: Alexander Lakhin Cc: pgsql-hackers@lists.postgresql.org Subject: Re: Avoid orphaned objects dependencies, take 3 Message-ID: References: <62310067-6dc4-97ab-6724-7d3602b5056d@gmail.com> <403075e1-4d60-09e2-a06a-749cd9d88f66@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <403075e1-4d60-09e2-a06a-749cd9d88f66@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, On Thu, Apr 25, 2024 at 09:00:00AM +0300, Alexander Lakhin wrote: > Hi, > > 25.04.2024 08:00, Bertrand Drouvot wrote: > > > > > though concurrent create/drop operations can still produce > > > the "cache lookup failed" error, which is probably okay, except that it is > > > an INTERNAL_ERROR, which assumed to be not easily triggered by users. > > I did not see any of those "cache lookup failed" during my testing with/without > > your script. During which test(s) did you see those with v3 applied? > > You can try, for example, table-trigger, or other tests that check for > "cache lookup failed" psql output only (maybe you'll need to increase the > iteration count). For instance, I've got (with v4 applied): > 2024-04-25 05:48:08.102 UTC [3638763] ERROR:  cache lookup failed for function 20893 > 2024-04-25 05:48:08.102 UTC [3638763] STATEMENT:  CREATE TRIGGER modified_c1 BEFORE UPDATE OF c ON t >         FOR EACH ROW WHEN (OLD.c <> NEW.c) EXECUTE PROCEDURE trigger_func('modified_c'); > > Or with function-function: > 2024-04-25 05:52:31.390 UTC [3711897] ERROR:  cache lookup failed for function 32190 at character 54 > 2024-04-25 05:52:31.390 UTC [3711897] STATEMENT:  CREATE FUNCTION f1() RETURNS int LANGUAGE SQL RETURN f() + 1; > -- > 2024-04-25 05:52:37.639 UTC [3720011] ERROR:  cache lookup failed for function 34465 at character 54 > 2024-04-25 05:52:37.639 UTC [3720011] STATEMENT:  CREATE FUNCTION f1() RETURNS int LANGUAGE SQL RETURN f() + 1; I see, so this is during object creation. It's easy to reproduce this kind of issue with gdb. For example set a breakpoint on SearchSysCache1() and during the create function f1() once it breaks on: #0 SearchSysCache1 (cacheId=45, key1=16400) at syscache.c:221 #1 0x00005ad305beacd6 in func_get_detail (funcname=0x5ad308204d50, fargs=0x0, fargnames=0x0, nargs=0, argtypes=0x7ffff2ff9cc0, expand_variadic=true, expand_defaults=true, include_out_arguments=false, funcid=0x7ffff2ff9ba0, rettype=0x7ffff2ff9b9c, retset=0x7ffff2ff9b94, nvargs=0x7ffff2ff9ba4, vatype=0x7ffff2ff9ba8, true_typeids=0x7ffff2ff9bd8, argdefaults=0x7ffff2ff9be0) at parse_func.c:1622 #2 0x00005ad305be7dd0 in ParseFuncOrColumn (pstate=0x5ad30823be98, funcname=0x5ad308204d50, fargs=0x0, last_srf=0x0, fn=0x5ad308204da0, proc_call=false, location=55) at parse_func.c:266 #3 0x00005ad305bdffb0 in transformFuncCall (pstate=0x5ad30823be98, fn=0x5ad308204da0) at parse_expr.c:1474 #4 0x00005ad305bdd2ee in transformExprRecurse (pstate=0x5ad30823be98, expr=0x5ad308204da0) at parse_expr.c:230 #5 0x00005ad305bdec34 in transformAExprOp (pstate=0x5ad30823be98, a=0x5ad308204e20) at parse_expr.c:990 #6 0x00005ad305bdd1a0 in transformExprRecurse (pstate=0x5ad30823be98, expr=0x5ad308204e20) at parse_expr.c:187 #7 0x00005ad305bdd00b in transformExpr (pstate=0x5ad30823be98, expr=0x5ad308204e20, exprKind=EXPR_KIND_SELECT_TARGET) at parse_expr.c:131 #8 0x00005ad305b96b7e in transformReturnStmt (pstate=0x5ad30823be98, stmt=0x5ad308204ee0) at analyze.c:2395 #9 0x00005ad305b92213 in transformStmt (pstate=0x5ad30823be98, parseTree=0x5ad308204ee0) at analyze.c:375 #10 0x00005ad305c6321a in interpret_AS_clause (languageOid=14, languageName=0x5ad308204c40 "sql", funcname=0x5ad308204ad8 "f100", as=0x0, sql_body_in=0x5ad308204ee0, parameterTypes=0x0, inParameterNames=0x0, prosrc_str_p=0x7ffff2ffa208, probin_str_p=0x7ffff2ffa200, sql_body_out=0x7ffff2ffa210, queryString=0x5ad3082040b0 "CREATE FUNCTION f100() RETURNS int LANGUAGE SQL RETURN f() + 1;") at functioncmds.c:953 #11 0x00005ad305c63c93 in CreateFunction (pstate=0x5ad308186310, stmt=0x5ad308204f00) at functioncmds.c:1221 then drop function f() in another session. Then the create function f1() would: postgres=# CREATE FUNCTION f() RETURNS int LANGUAGE SQL RETURN f() + 1; ERROR: cache lookup failed for function 16400 This stuff does appear before we get a chance to call the new depLockAndCheckObject() function. I think this is what Tom was referring to in [1]: " So the only real fix for this would be to make every object lookup in the entire system do the sort of dance that's done in RangeVarGetRelidExtended. " The fact that those kind of errors appear also somehow ensure that no orphaned dependencies can be created. The patch does ensure that no orphaned depencies can occur after those "initial" look up are done (should the dependent object be dropped). I'm tempted to not add extra complexity to avoid those kind of errors and keep the patch as it is. All of those servicing the same goal: no orphaned depencies are created. [1]: https://www.postgresql.org/message-id/2872252.1630851337%40sss.pgh.pa.us Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com