1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Disallow partition key expressions that return pseudo-types.

This wasn't checked originally, but it should have been, because
in general pseudo-types can't be stored to and retrieved from disk.
Notably, partition bound values of type "record" would not be
interpretable by another session.

In v12 and HEAD, add another flag to CheckAttributeType's repertoire
so that it can produce a specific error message for this case.  That's
infeasible in older branches without an ABI break, so fall back to
a slightly-less-nicely-worded error message in v10 and v11.

Problem noted by Amit Langote, though this patch is not his initial
solution.  Back-patch to v10 where partitioning was introduced.

Discussion: https://postgr.es/m/CA+HiwqFUzjfj9HEsJtYWcr1SgQ_=iCAvQ=O2Sx6aQxoDu4OiHw@mail.gmail.com
This commit is contained in:
Tom Lane
2019-12-23 12:53:13 -05:00
parent 976cb11f6c
commit 7fbb39a967
5 changed files with 71 additions and 14 deletions

View File

@ -375,7 +375,7 @@ CREATE TABLE partitioned (
ERROR: cannot use subquery in partition key expression
CREATE TABLE partitioned (
a int
) PARTITION BY RANGE (('a'));
) PARTITION BY RANGE ((42));
ERROR: cannot use constant expression as partition key
CREATE FUNCTION const_func () RETURNS int AS $$ SELECT 1; $$ LANGUAGE SQL IMMUTABLE;
CREATE TABLE partitioned (
@ -402,6 +402,17 @@ CREATE TABLE partitioned (
ERROR: cannot use system column "xmin" in partition key
LINE 3: ) PARTITION BY RANGE (xmin);
^
-- cannot use pseudotypes
CREATE TABLE partitioned (
a int,
b int
) PARTITION BY RANGE (((a, b)));
ERROR: partition key column 1 has pseudo-type record
CREATE TABLE partitioned (
a int,
b int
) PARTITION BY RANGE (a, ('unknown'));
ERROR: partition key column 2 has pseudo-type unknown
-- functions in key must be immutable
CREATE FUNCTION immut_func (a int) RETURNS int AS $$ SELECT a + random()::int; $$ LANGUAGE SQL;
CREATE TABLE partitioned (

View File

@ -361,7 +361,7 @@ CREATE TABLE partitioned (
CREATE TABLE partitioned (
a int
) PARTITION BY RANGE (('a'));
) PARTITION BY RANGE ((42));
CREATE FUNCTION const_func () RETURNS int AS $$ SELECT 1; $$ LANGUAGE SQL IMMUTABLE;
CREATE TABLE partitioned (
@ -384,6 +384,16 @@ CREATE TABLE partitioned (
a int
) PARTITION BY RANGE (xmin);
-- cannot use pseudotypes
CREATE TABLE partitioned (
a int,
b int
) PARTITION BY RANGE (((a, b)));
CREATE TABLE partitioned (
a int,
b int
) PARTITION BY RANGE (a, ('unknown'));
-- functions in key must be immutable
CREATE FUNCTION immut_func (a int) RETURNS int AS $$ SELECT a + random()::int; $$ LANGUAGE SQL;
CREATE TABLE partitioned (