pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix timing issue with ALTER TABLE's validate constraint
7+ messages / 1 participants
[nested] [flat]

* pgsql: Fix timing issue with ALTER TABLE's validate constraint
@ 2020-07-14 05:02 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2020-07-14 05:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix timing issue with ALTER TABLE's validate constraint

An ALTER TABLE to validate a foreign key in which another subcommand
already caused a pending table rewrite could fail due to ALTER TABLE
attempting to validate the foreign key before the actual table rewrite
takes place.  This situation could result in an error such as:

ERROR:  could not read block 0 in file "base/nnnnn/nnnnn": read only 0 of 8192 bytes

The failure here was due to the SPI call which validates the foreign key
trying to access an index which is yet to be rebuilt.

Similarly, we also incorrectly tried to validate CHECK constraints before
the heap had been rewritten.

The fix for both is to delay constraint validation until phase 3, after
the table has been rewritten.  For CHECK constraints this means a slight
behavioral change.  Previously ALTER TABLE VALIDATE CONSTRAINT on
inheritance tables would be validated from the bottom up.  This was
different from the order of evaluation when a new CHECK constraint was
added.  The changes made here aligns the VALIDATE CONSTRAINT evaluation
order for inheritance tables to be the same as ADD CONSTRAINT, which is
generally top-down.

Reported-by: Nazli Ugur Koyluoglu, using SQLancer
Discussion: https://postgr.es/m/CAApHDvp%3DZXv8wiRyk_0rWr00skhGkt8vXDrHJYXRMft3TjkxCA%40mail.gmail.com
Backpatch-through: 9.5 (all supported versions)

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/f1fcf2d3b2e00b3d7ad3e0d2b1d26b77f5a48413

Modified Files
--------------
src/backend/commands/tablecmds.c          | 155 ++++++++++--------------------
src/test/regress/expected/alter_table.out |  22 ++++-
src/test/regress/sql/alter_table.sql      |  22 +++++
3 files changed, 93 insertions(+), 106 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix timing issue with ALTER TABLE's validate constraint
@ 2020-07-14 05:02 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2020-07-14 05:02 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix timing issue with ALTER TABLE's validate constraint

An ALTER TABLE to validate a foreign key in which another subcommand
already caused a pending table rewrite could fail due to ALTER TABLE
attempting to validate the foreign key before the actual table rewrite
takes place.  This situation could result in an error such as:

ERROR:  could not read block 0 in file "base/nnnnn/nnnnn": read only 0 of 8192 bytes

The failure here was due to the SPI call which validates the foreign key
trying to access an index which is yet to be rebuilt.

Similarly, we also incorrectly tried to validate CHECK constraints before
the heap had been rewritten.

The fix for both is to delay constraint validation until phase 3, after
the table has been rewritten.  For CHECK constraints this means a slight
behavioral change.  Previously ALTER TABLE VALIDATE CONSTRAINT on
inheritance tables would be validated from the bottom up.  This was
different from the order of evaluation when a new CHECK constraint was
added.  The changes made here aligns the VALIDATE CONSTRAINT evaluation
order for inheritance tables to be the same as ADD CONSTRAINT, which is
generally top-down.

Reported-by: Nazli Ugur Koyluoglu, using SQLancer
Discussion: https://postgr.es/m/CAApHDvp%3DZXv8wiRyk_0rWr00skhGkt8vXDrHJYXRMft3TjkxCA%40mail.gmail.com
Backpatch-through: 9.5 (all supported versions)

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/b827304291aff8019cdd0cee68219fe43f064380

Modified Files
--------------
src/backend/commands/tablecmds.c          | 155 ++++++++++--------------------
src/test/regress/expected/alter_table.out |  22 ++++-
src/test/regress/sql/alter_table.sql      |  22 +++++
3 files changed, 93 insertions(+), 106 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix timing issue with ALTER TABLE's validate constraint
@ 2020-07-14 05:03 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2020-07-14 05:03 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix timing issue with ALTER TABLE's validate constraint

An ALTER TABLE to validate a foreign key in which another subcommand
already caused a pending table rewrite could fail due to ALTER TABLE
attempting to validate the foreign key before the actual table rewrite
takes place.  This situation could result in an error such as:

ERROR:  could not read block 0 in file "base/nnnnn/nnnnn": read only 0 of 8192 bytes

The failure here was due to the SPI call which validates the foreign key
trying to access an index which is yet to be rebuilt.

Similarly, we also incorrectly tried to validate CHECK constraints before
the heap had been rewritten.

The fix for both is to delay constraint validation until phase 3, after
the table has been rewritten.  For CHECK constraints this means a slight
behavioral change.  Previously ALTER TABLE VALIDATE CONSTRAINT on
inheritance tables would be validated from the bottom up.  This was
different from the order of evaluation when a new CHECK constraint was
added.  The changes made here aligns the VALIDATE CONSTRAINT evaluation
order for inheritance tables to be the same as ADD CONSTRAINT, which is
generally top-down.

Reported-by: Nazli Ugur Koyluoglu, using SQLancer
Discussion: https://postgr.es/m/CAApHDvp%3DZXv8wiRyk_0rWr00skhGkt8vXDrHJYXRMft3TjkxCA%40mail.gmail.com
Backpatch-through: 9.5 (all supported versions)

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1231a0b0ea66df231875a7470a74ac060f5b9b97

Modified Files
--------------
src/backend/commands/tablecmds.c          | 155 ++++++++++--------------------
src/test/regress/expected/alter_table.out |  22 ++++-
src/test/regress/sql/alter_table.sql      |  22 +++++
3 files changed, 94 insertions(+), 105 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix timing issue with ALTER TABLE's validate constraint
@ 2020-07-14 05:03 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2020-07-14 05:03 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix timing issue with ALTER TABLE's validate constraint

An ALTER TABLE to validate a foreign key in which another subcommand
already caused a pending table rewrite could fail due to ALTER TABLE
attempting to validate the foreign key before the actual table rewrite
takes place.  This situation could result in an error such as:

ERROR:  could not read block 0 in file "base/nnnnn/nnnnn": read only 0 of 8192 bytes

The failure here was due to the SPI call which validates the foreign key
trying to access an index which is yet to be rebuilt.

Similarly, we also incorrectly tried to validate CHECK constraints before
the heap had been rewritten.

The fix for both is to delay constraint validation until phase 3, after
the table has been rewritten.  For CHECK constraints this means a slight
behavioral change.  Previously ALTER TABLE VALIDATE CONSTRAINT on
inheritance tables would be validated from the bottom up.  This was
different from the order of evaluation when a new CHECK constraint was
added.  The changes made here aligns the VALIDATE CONSTRAINT evaluation
order for inheritance tables to be the same as ADD CONSTRAINT, which is
generally top-down.

Reported-by: Nazli Ugur Koyluoglu, using SQLancer
Discussion: https://postgr.es/m/CAApHDvp%3DZXv8wiRyk_0rWr00skhGkt8vXDrHJYXRMft3TjkxCA%40mail.gmail.com
Backpatch-through: 9.5 (all supported versions)

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/d2761b680a9052b9d62912cfcc36c154f28517ce

Modified Files
--------------
src/backend/commands/tablecmds.c          | 162 ++++++++++--------------------
src/test/regress/expected/alter_table.out |  22 +++-
src/test/regress/sql/alter_table.sql      |  22 ++++
3 files changed, 95 insertions(+), 111 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix timing issue with ALTER TABLE's validate constraint
@ 2020-07-14 05:04 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2020-07-14 05:04 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix timing issue with ALTER TABLE's validate constraint

An ALTER TABLE to validate a foreign key in which another subcommand
already caused a pending table rewrite could fail due to ALTER TABLE
attempting to validate the foreign key before the actual table rewrite
takes place.  This situation could result in an error such as:

ERROR:  could not read block 0 in file "base/nnnnn/nnnnn": read only 0 of 8192 bytes

The failure here was due to the SPI call which validates the foreign key
trying to access an index which is yet to be rebuilt.

Similarly, we also incorrectly tried to validate CHECK constraints before
the heap had been rewritten.

The fix for both is to delay constraint validation until phase 3, after
the table has been rewritten.  For CHECK constraints this means a slight
behavioral change.  Previously ALTER TABLE VALIDATE CONSTRAINT on
inheritance tables would be validated from the bottom up.  This was
different from the order of evaluation when a new CHECK constraint was
added.  The changes made here aligns the VALIDATE CONSTRAINT evaluation
order for inheritance tables to be the same as ADD CONSTRAINT, which is
generally top-down.

Reported-by: Nazli Ugur Koyluoglu, using SQLancer
Discussion: https://postgr.es/m/CAApHDvp%3DZXv8wiRyk_0rWr00skhGkt8vXDrHJYXRMft3TjkxCA%40mail.gmail.com
Backpatch-through: 9.5 (all supported versions)

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/4e02f88a4eedd2f9808c16d6d7b50c3a78af2d39

Modified Files
--------------
src/backend/commands/tablecmds.c          | 162 ++++++++++--------------------
src/test/regress/expected/alter_table.out |  22 +++-
src/test/regress/sql/alter_table.sql      |  22 ++++
3 files changed, 95 insertions(+), 111 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix timing issue with ALTER TABLE's validate constraint
@ 2020-07-14 05:04 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2020-07-14 05:04 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix timing issue with ALTER TABLE's validate constraint

An ALTER TABLE to validate a foreign key in which another subcommand
already caused a pending table rewrite could fail due to ALTER TABLE
attempting to validate the foreign key before the actual table rewrite
takes place.  This situation could result in an error such as:

ERROR:  could not read block 0 in file "base/nnnnn/nnnnn": read only 0 of 8192 bytes

The failure here was due to the SPI call which validates the foreign key
trying to access an index which is yet to be rebuilt.

Similarly, we also incorrectly tried to validate CHECK constraints before
the heap had been rewritten.

The fix for both is to delay constraint validation until phase 3, after
the table has been rewritten.  For CHECK constraints this means a slight
behavioral change.  Previously ALTER TABLE VALIDATE CONSTRAINT on
inheritance tables would be validated from the bottom up.  This was
different from the order of evaluation when a new CHECK constraint was
added.  The changes made here aligns the VALIDATE CONSTRAINT evaluation
order for inheritance tables to be the same as ADD CONSTRAINT, which is
generally top-down.

Reported-by: Nazli Ugur Koyluoglu, using SQLancer
Discussion: https://postgr.es/m/CAApHDvp%3DZXv8wiRyk_0rWr00skhGkt8vXDrHJYXRMft3TjkxCA%40mail.gmail.com
Backpatch-through: 9.5 (all supported versions)

Branch
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/c732df133a3d4ad32b9fb35f2f1b15cb08ac6b3a

Modified Files
--------------
src/backend/commands/tablecmds.c          | 159 ++++++++++--------------------
src/test/regress/expected/alter_table.out |  22 ++++-
src/test/regress/sql/alter_table.sql      |  22 +++++
3 files changed, 95 insertions(+), 108 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread

* pgsql: Fix timing issue with ALTER TABLE's validate constraint
@ 2020-07-14 05:04 David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2020-07-14 05:04 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix timing issue with ALTER TABLE's validate constraint

An ALTER TABLE to validate a foreign key in which another subcommand
already caused a pending table rewrite could fail due to ALTER TABLE
attempting to validate the foreign key before the actual table rewrite
takes place.  This situation could result in an error such as:

ERROR:  could not read block 0 in file "base/nnnnn/nnnnn": read only 0 of 8192 bytes

The failure here was due to the SPI call which validates the foreign key
trying to access an index which is yet to be rebuilt.

Similarly, we also incorrectly tried to validate CHECK constraints before
the heap had been rewritten.

The fix for both is to delay constraint validation until phase 3, after
the table has been rewritten.  For CHECK constraints this means a slight
behavioral change.  Previously ALTER TABLE VALIDATE CONSTRAINT on
inheritance tables would be validated from the bottom up.  This was
different from the order of evaluation when a new CHECK constraint was
added.  The changes made here aligns the VALIDATE CONSTRAINT evaluation
order for inheritance tables to be the same as ADD CONSTRAINT, which is
generally top-down.

Reported-by: Nazli Ugur Koyluoglu, using SQLancer
Discussion: https://postgr.es/m/CAApHDvp%3DZXv8wiRyk_0rWr00skhGkt8vXDrHJYXRMft3TjkxCA%40mail.gmail.com
Backpatch-through: 9.5 (all supported versions)

Branch
------
REL9_5_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/e20003fa0f8d35fa03bc60273e1cee4558f19e41

Modified Files
--------------
src/backend/commands/tablecmds.c          | 159 ++++++++++--------------------
src/test/regress/expected/alter_table.out |  22 ++++-
src/test/regress/sql/alter_table.sql      |  22 +++++
3 files changed, 95 insertions(+), 108 deletions(-)



^ permalink  raw  reply  [nested|flat] 7+ messages in thread


end of thread, other threads:[~2020-07-14 05:04 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-07-14 05:02 pgsql: Fix timing issue with ALTER TABLE's validate constraint David Rowley <drowley@postgresql.org>
2020-07-14 05:02 pgsql: Fix timing issue with ALTER TABLE's validate constraint David Rowley <drowley@postgresql.org>
2020-07-14 05:03 pgsql: Fix timing issue with ALTER TABLE's validate constraint David Rowley <drowley@postgresql.org>
2020-07-14 05:03 pgsql: Fix timing issue with ALTER TABLE's validate constraint David Rowley <drowley@postgresql.org>
2020-07-14 05:04 pgsql: Fix timing issue with ALTER TABLE's validate constraint David Rowley <drowley@postgresql.org>
2020-07-14 05:04 pgsql: Fix timing issue with ALTER TABLE's validate constraint David Rowley <drowley@postgresql.org>
2020-07-14 05:04 pgsql: Fix timing issue with ALTER TABLE's validate constraint David Rowley <drowley@postgresql.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox