Re: using index or check in ALTER TABLE SET NOT NULL
Ildar Musin <i.musin@postgrespro.ru>
From: Ildar Musin <i.musin@postgrespro.ru>
To: Tom Lane <tgl@sss.pgh.pa.us>, Sergei Kornilov <sk@zsrv.org>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>,
Stephen Frost <sfrost@snowman.net>, Robert Haas <robertmhaas@gmail.com>,
"pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2018-03-07T11:03:53Z
Lists: pgsql-hackers
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
Commits
-
Avoid using INFO elevel for what are fundamentally debug messages.
- db438318997b 13.0 landed
- 121e3ceed6d9 12.0 landed
-
Revert setting client_min_messages to 'debug1' in new tests.
- 5655565c077c 12.0 landed
-
Allow ALTER TABLE .. SET NOT NULL to skip provably unnecessary scans.
- bbb96c3704c0 12.0 landed
-
Improve predtest.c's internal docs, and enhance its functionality a bit.
- 5748f3a0aa7c 11.0 cited