postgresql/src/test/regress
Alvaro Herrera 705d433fd5 Revise attribute handling code on partition creation
The original code to propagate NOT NULL and default expressions
specified when creating a partition was mostly copy-pasted from
typed-tables creation, but not being a great match it contained some
duplicity, inefficiency and bugs.

This commit fixes the bug that NOT NULL constraints declared in the
parent table would not be honored in the partition.  One reported issue
that is not fixed is that a DEFAULT declared in the child is not used
when inserting through the parent.  That would amount to a behavioral
change that's better not back-patched.

This rewrite makes the code simpler:

1. instead of checking for duplicate column names in its own block,
reuse the original one that already did that;

2. instead of concatenating the list of columns from parent and the one
declared in the partition and scanning the result to (incorrectly)
propagate defaults and not-null constraints, just scan the latter
searching the former for a match, and merging sensibly.  This works
because we know the list in the parent is already correct and there can
only be one parent.

This rewrite makes ColumnDef->is_from_parent unused, so it's removed
on branch master; on released branches, it's kept as an unused field in
order not to cause ABI incompatibilities.

This commit also adds a test case for creating partitions with
collations mismatching that on the parent table, something that is
closely related to the code being patched.  No code change is introduced
though, since that'd be a behavior change that could break some (broken)
working applications.

Amit Langote wrote a less invasive fix for the original
NOT NULL/defaults bug, but while I kept the tests he added, I ended up
not using his original code.  Ashutosh Bapat reviewed Amit's fix.  Amit
reviewed mine.

Author: Álvaro Herrera, Amit Langote
Reviewed-by: Ashutosh Bapat, Amit Langote
Reported-by: Jürgen Strobel (bug #15212)
Discussion: https://postgr.es/m/152746742177.1291.9847032632907407358@wrigleys.postgresql.org
2018-11-08 16:22:09 -03:00
..
data
expected Revise attribute handling code on partition creation 2018-11-08 16:22:09 -03:00
input Fix tablespace handling for partitioned indexes 2018-11-03 13:25:19 -03:00
output Fix tablespace handling for partitioned indexes 2018-11-03 13:25:19 -03:00
sql Revise attribute handling code on partition creation 2018-11-08 16:22:09 -03:00
.gitignore
GNUmakefile
Makefile
parallel_schedule Disable recheck_on_update optimization to avoid crashes. 2018-11-06 18:33:28 -05:00
pg_regress_main.c Clean up assorted misuses of snprintf()'s result value. 2018-08-15 16:29:31 -04:00
pg_regress.c Lower privilege level of programs calling regression_main 2018-10-20 09:02:36 -04:00
pg_regress.h
README
regress.c Refactor geometric functions and operators 2018-07-29 02:36:29 +02:00
regressplans.sh
resultmap Make float exponent output on Windows look the same as elsewhere. 2018-10-12 11:14:27 -04:00
serial_schedule Disable recheck_on_update optimization to avoid crashes. 2018-11-06 18:33:28 -05:00
standby_schedule

Documentation concerning how to run these regression tests and interpret
the results can be found in the PostgreSQL manual, in the chapter
"Regression Tests".