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 1qqsUF-001V65-9F for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Oct 2023 10:00:11 +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 1qqsUC-005PsY-Sf for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Oct 2023 10:00:09 +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 1qqsUC-005PsQ-J4 for pgsql-hackers@lists.postgresql.org; Thu, 12 Oct 2023 10:00:09 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qqsU8-00095S-TY for pgsql-hackers@lists.postgresql.org; Thu, 12 Oct 2023 10:00:08 +0000 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-5045cb9c091so1136588e87.3 for ; Thu, 12 Oct 2023 03:00:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697104804; x=1697709604; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=0gHcpnkzTMEAe19LOsf0OS6G8ZmX9iD18O30Cg2kE6c=; b=cC0xoLec8/ysXbs3HCzpREN9tLTFAYIDm2/IhkiM7DkXVgAdJWY17ZCMv6OGJVTuq1 KZIKc3OX22tKMb5go27yVySEwTzDD7gsk8d9e5IuEwlaXWQxjX0G/pdnF6+utAa1vazY G4ybIuzbdBez6e1KmOER2wTOiJ7Z7TEHutkbFrpCnwBX474JJ8uCKD2RBcf3cyr1f/ch LNNfdf/kWtYmFw3VXoOYBgWpaJJ0KSgcWWEF68178LhwOftTwrzqPrjmN3/sL9FPE4t4 UceKgTQCYlTF8TQUxUg3lkVnl40vWRbd1fzhc1ShjG5D6l5Kfdq4cKCq7HiHCbUqYgiM w1RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697104804; x=1697709604; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0gHcpnkzTMEAe19LOsf0OS6G8ZmX9iD18O30Cg2kE6c=; b=fKh5VyjECK4ZWQESOUaWUOvS/D/GStK06/vW1Ok/BCntSoGhqpsmb/0a77NbeqzKLI 1SiQRwMATfSL8/8GAHKhsHn7VBbmihsSOvjMdaW49B2Hj+IaJe80n/E7Q8U6UgQ9xsj2 gOt/YoSG7ykFe6Wo/IynSmDAduqF4jYlFtgJ9ROtuS7egoLLz5P5taEtT2bLt25jWGB/ iK+u56ReG71vThuD3YGVyynKmTddWzwNtGIejdCaU6anU7OQu7yiyWM/uuZc9bDYViQ+ 8s5t1DwdmfYjtV4/vRutnYUDYhYrd3NmByW2tPOag7osW04NKbv/xbTBt28Woy0vjKzI n/Eg== X-Gm-Message-State: AOJu0Yyhvyc/BlaLyaisEtg4XePn3BXIXHozs676oisXJLfDXpCqpgoh aslJ0u3lydjQmYEOwzA9CxQ= X-Google-Smtp-Source: AGHT+IFykq4CWBqJnZMm9vtyjT0g/C79llTLy+SR2Z0nBzsCmGU4hupBe2OiLzgUjyVsuzZPGb4TwQ== X-Received: by 2002:ac2:5b9e:0:b0:500:c765:bbe with SMTP id o30-20020ac25b9e000000b00500c7650bbemr16883220lfn.0.1697104804025; Thu, 12 Oct 2023 03:00:04 -0700 (PDT) Received: from [1.0.0.7] ([81.23.166.137]) by smtp.gmail.com with ESMTPSA id h12-20020a19700c000000b00505776abca8sm2715056lfc.48.2023.10.12.03.00.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Oct 2023 03:00:02 -0700 (PDT) Message-ID: Date: Thu, 12 Oct 2023 13:00:01 +0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: cataloguing NOT NULL constraints Content-Language: en-US To: Alvaro Herrera , Dean Rasheed , Peter Eisentraut Cc: Robert Haas , pgsql-hackers@lists.postgresql.org References: <20230825113833.4li4xnii2h4r3mqd@alvherre.pgsql> From: Alexander Lakhin In-Reply-To: <20230825113833.4li4xnii2h4r3mqd@alvherre.pgsql> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Alvaro, 25.08.2023 14:38, Alvaro Herrera wrote: > I have now pushed this again. Hopefully it'll stick this time. I've discovered that that commit added several recursive functions, and some of them are not protected from stack overflow. Namely, with "max_locks_per_transaction = 600" and default ulimit -s (8192), I observe server crashes with the following scripts: # ATExecSetNotNull() (n=40000; printf "create table t0 (a int, b int);"; for ((i=1;i<=$n;i++)); do printf "create table t$i() inherits(t$(( $i - 1 ))); "; done; printf "alter table t0 alter b set not null;" ) | psql >psql.log # dropconstraint_internal() (n=20000; printf "create table t0 (a int, b int not null);"; for ((i=1;i<=$n;i++)); do printf "create table t$i() inherits(t$(( $i - 1 ))); "; done; printf "alter table t0 alter b drop not null;" ) | psql >psql.log # set_attnotnull() (n=110000; printf "create table tp (a int, b int, primary key(a, b)) partition by range (a); create table tp0 (a int primary key, b int) partition by range (a);"; for ((i=1;i<=$n;i++)); do printf "create table tp$i partition of tp$(( $i - 1 )) for values from ($i) to (1000000) partition by range (a);"; done; printf "alter table tp attach partition tp0 for values from (0) to (1000000);") | psql >psql.log # this takes half an hour on my machine May be you would find appropriate to add check_stack_depth() to these functions. (ATAddCheckNNConstraint() is protected because it calls AddRelationNewConstraints(), which in turn calls StoreRelCheck() -> CreateConstraintEntry() ->  recordDependencyOnSingleRelExpr() -> find_expr_references_walker() ->  expression_tree_walker() -> expression_tree_walker() -> check_stack_depth().) (There were patches prepared for similar cases [1], but they don't cover new functions, of course, and I'm not sure how to handle all such instances.) [1] https://commitfest.postgresql.org/45/4239/ Best regards, Alexander