Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1etWrY-0006sv-C8 for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Mar 2018 11:04:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1etWrX-0004AE-3O for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Mar 2018 11:03:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1etWrW-0004A4-PQ for pgsql-hackers@lists.postgresql.org; Wed, 07 Mar 2018 11:03:58 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1etWrU-0004sE-3U for pgsql-hackers@postgresql.org; Wed, 07 Mar 2018 11:03:58 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 1B22D21C1C57; Wed, 7 Mar 2018 14:03:54 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.109] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id C0F4321C1C4F; Wed, 7 Mar 2018 14:03:53 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1520420633; bh=S3gYdLQ+y4H8mKi9IwWnWljxcsO0D93xrp179FE2+y0=; h=Subject:To:References:Cc:From:Date:In-Reply-To; b=qG+RdD3yCnCId/2EkHvB3kKkxAaMz5qwjrjglGAC24+qKh+//Wzd1L4r1Ta5MKk3M N0uG4wyighTfl+/vM42r0pKtYRPKl/sC9VEnIGYuMkJTbNoFDEZpnIwW+i2CDYJaBw QSuEhbY/7awqyURAThbYlHrcVM7FAbFaFLcyu5/g= Subject: Re: using index or check in ALTER TABLE SET NOT NULL To: Tom Lane , Sergei Kornilov References: <880511520351578@web5j.yandex.ru> <20180306172528.xnelm3xcq2qeyd2g@alvherre.pgsql> <1715451520361128@web26o.yandex.ru> <1142.1520362313@sss.pgh.pa.us> Cc: Alvaro Herrera , Stephen Frost , Robert Haas , "pgsql-hackers@postgresql.org" From: Ildar Musin Message-ID: <082cf493-a989-dcd6-7baf-a94a40d07ea0@postgrespro.ru> Date: Wed, 7 Mar 2018 14:03:53 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <1142.1520362313@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello Sergei, Alvaro, Tom, On 06.03.2018 20:25, Alvaro Herrera wrote: > You should be able to use an event trigger that raises a message when > table_rewrite is hit, to notify the test driver that a rewrite happens. > > (If any DDL that causes a table rewrite fails to trigger the > table_rewrite event correctly, that is a bug.) > It seems that 'table_rewrite' event trigger isn't fired in case of simple scan (without actual rewrite). > ISTM that depending on DEBUG messages is bad because debugging lines > added elsewhere will make your tests fail; I think that between test depending on DEBUG message and no test at all the former one is preferable. Are there other options to test it? On 06.03.2018 21:51, Tom Lane wrote: > > Do you actually need test output proving that this code path was taken > rather than the default one? Seems like looking at the code coverage > report might be enough. > Code coverage cannot guarantee correctness. I think there should be at least two tests: * full scan is performed when there are no check constraints that restrict NULL values; * full scan is omitted when there are such constraints. The last one could also include some unobvious cases like CHECK (col > 0), complex expressions with boolean operators etc. PS: Btw, some check constraints that implies NOT NULL still won't prevent from full table scan. For instance: # create table test (a int, b int check ((a + b) is not null)); CREATE TABLE # set client_min_messages to 'debug1'; SET # insert into test values (1, 1); INSERT 0 1 # alter table test alter column a set not null; DEBUG: verifying table "test" <<<< full table scan! ALTER TABLE Since operator+ (aka int4pl) is strict it returns NULL if at least one of its operands is NULL. And this check constraint ensures therefore that both columns 'a' and 'b' are NOT NULL. It isn't probably the issue of this patch, just something that someone may find interesting. -- Ildar Musin i.musin@postgrespro.ru