Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cgCjt-0002wr-05 for pgsql-bugs@arkaria.postgresql.org; Tue, 21 Feb 2017 15:52:29 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cgCjs-0000fH-Hp for pgsql-bugs@arkaria.postgresql.org; Tue, 21 Feb 2017 15:52:28 +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.84_2) (envelope-from ) id 1cgCjA-0008Gk-9K for pgsql-bugs@postgresql.org; Tue, 21 Feb 2017 15:51:44 +0000 Received: from mail-qt0-x233.google.com ([2607:f8b0:400d:c0d::233]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1cgCj3-0005RG-44 for pgsql-bugs@postgresql.org; Tue, 21 Feb 2017 15:51:42 +0000 Received: by mail-qt0-x233.google.com with SMTP id x35so40834774qtc.2 for ; Tue, 21 Feb 2017 07:51:36 -0800 (PST) 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=JmuYHiuCbwyeZW/syO3ng07sams9rPEdAlq9mgx/bu4=; b=XZRtKBl8rFX0UqZmn9hEfQQY7iChxObon1hjeDJrPT/APwH/8kKGFvDb2a3lgckw1T lmIzVRgE5JbdCVypeTN+TQTRjk6fL/XKLYnGfmhcKUqzBmT/1GTwhmgclOBAYhvmlcRa LwIUp/TW+mW/rCImMv2Nvxn2Dct1znVABPJ8nnkGON0CfnDKUO1cuENC3Q4uZlbG+hjP hqUrgc1T3EvNSfpKX16sx/mBWq2heL4WCDGbLoNg5PbvuPSDLf2nTP9zjx9hyfKAT4CD vbbByCid6NHRp8W+5lrMHH3oVELMS5OhhRiJPyAOS+yqDHUKQ73/wbokRzLa90CcXkIx yNdg== 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=JmuYHiuCbwyeZW/syO3ng07sams9rPEdAlq9mgx/bu4=; b=YrGgGy6H3HMr5pmlX5Aa9gxIhEwqaHBLJZEyHYTvPTHHfjXno5L8rJy21bsvCID5O/ YqCfKWsNlSJ8e3ovf8VCaWLLOIxLdZ0lsMSso6y/OQSaI9e1EZrpt8vToVo+BVL/yF3O 2ZenACh7ZY2oLAyblbhIuBZWxw6DumQNSjMw1ffaDEX+T0fJZlN1bW5PFMLg29kbAdMy BPv8s3TaSO4piAGpz2aFtJ4BPDqtdfzVTZwr0CC2XD88zMQr3PHtSD4lAsVNxvsHc5B5 AWRDT7RU7BQSmUXwJobpUST3332LSew8AQUxwZrZovaEbvSanfTrvDF3vekO9HOt48tQ qf2Q== X-Gm-Message-State: AMke39m4gnYew9wCOKP9fEVOqS0rdADqDy1qbqobhRcVo6dFMjY6tupx7V/sirKU6Whtw/pRKwUWmPFXNKTaPb6spMAHMvPGjGq9uPM72naWWGvYy7dhgHKbH504bj/tLm1CBWqsTz8PTET6vdxrlMbbt0bUCqwKH48L2XsuZ56UYErVPKbdF21kBhBNC44c2Wk= X-Received: by 10.200.54.207 with SMTP id b15mr12795337qtc.9.1487692296063; Tue, 21 Feb 2017 07:51:36 -0800 (PST) Received: from alvin.alvh.no-ip.org ([201.186.29.49]) by smtp.gmail.com with ESMTPSA id 12sm14199884qtv.31.2017.02.21.07.51.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 21 Feb 2017 07:51:35 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 7641E22A0; Tue, 21 Feb 2017 12:51:33 -0300 (CLST) Date: Tue, 21 Feb 2017 12:51:33 -0300 From: Alvaro Herrera To: Tom Lane Cc: amos_operation@swiss-as.com, pgsql-bugs@postgresql.org Subject: Re: BUG #14560: FK not valid are ignored during transactions Message-ID: <20170221155133.owzj7exrno5f3vht@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8123.1487691874@sss.pgh.pa.us> User-Agent: NeoMutt/20170206-195-7adf12 (1.7.2) X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Tom Lane wrote: > ADD table_constraint [ NOT VALID ] > > This form adds a new constraint to a table using the same syntax as > CREATE TABLE, plus the option NOT VALID, which is currently only > allowed for foreign key and CHECK constraints. If the constraint is > marked NOT VALID, the potentially-lengthy initial check to verify that > all rows in the table satisfy the constraint is skipped. The > constraint will still be enforced against subsequent inserts or > updates (that is, they'll fail unless there is a matching row in the > referenced table, in the case of foreign keys; and they'll fail unless > the new row matches the specified check constraints). But the database > will not assume that the constraint holds for all rows in the table, > until it is validated by using the VALIDATE CONSTRAINT option. > > So the behavior in the multiple-inserts-in-one-transaction case is as > documented. I think that the fact that you don't see an error when you > do only one row update per transaction is because we optimize away the > FK check entirely in that case (if the FK columns aren't changed, > obviously). I don't recall exactly why that optimization can't be used > for repeat updates in a single transaction. In any case, I don't see a > bug here; I think you are misunderstanding what NOT VALID is supposed > to do. I agree that this is working as intended and documented. However, note that the value in the referencing column does not change. I would expect a failure if the value changes from a matching value to a mismatching value; or from a mismatching value to another mismatching value. But if the value does not change, why are we checking it at all? Now, this is outside the initial intent for which NOT VALID was created, which is to separate the long verification table scan from the access exclusive lock. But I think there is room to say that, as a new feature, the proposed behavior ought to at least appear in the TODO list, if someone wants to have a stab at implementing it (not me). -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs