Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitea1205a

Browse files
committed
Disallow partition key expressions that return pseudo-types.
This wasn't checked originally, but it should have been, becausein general pseudo-types can't be stored to and retrieved from disk.Notably, partition bound values of type "record" would not beinterpretable by another session.In v12 and HEAD, add another flag to CheckAttributeType's repertoireso that it can produce a specific error message for this case. That'sinfeasible in older branches without an ABI break, so fall back toa slightly-less-nicely-worded error message in v10 and v11.Problem noted by Amit Langote, though this patch is not his initialsolution. Back-patch to v10 where partitioning was introduced.Discussion:https://postgr.es/m/CA+HiwqFUzjfj9HEsJtYWcr1SgQ_=iCAvQ=O2Sx6aQxoDu4OiHw@mail.gmail.com
1 parent4af2531 commitea1205a

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13423,6 +13423,16 @@ ComputePartitionAttrs(Relation rel, List *partParams, AttrNumber *partattrs,
1342313423
atttype=exprType(expr);
1342413424
attcollation=exprCollation(expr);
1342513425

13426+
/*
13427+
* The expression must be of a storable type (e.g., not RECORD).
13428+
* The test is the same as for whether a table column is of a safe
13429+
* type (which is why we needn't check for the non-expression
13430+
* case).
13431+
*/
13432+
CheckAttributeType("partition key",
13433+
atttype,attcollation,
13434+
NIL, false);
13435+
1342613436
/*
1342713437
* Strip any top-level COLLATE clause. This ensures that we treat
1342813438
* "x COLLATE y" and "(x COLLATE y)" alike.

‎src/test/regress/expected/create_table.out

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ CREATE TABLE partitioned (
341341
ERROR: cannot use subquery in partition key expression
342342
CREATE TABLE partitioned (
343343
a int
344-
) PARTITION BY RANGE (('a'));
344+
) PARTITION BY RANGE ((42));
345345
ERROR: cannot use constant expression as partition key
346346
CREATE FUNCTION const_func () RETURNS int AS $$ SELECT 1; $$ LANGUAGE SQL IMMUTABLE;
347347
CREATE TABLE partitioned (
@@ -364,6 +364,17 @@ CREATE TABLE partitioned (
364364
a int
365365
) PARTITION BY RANGE (xmin);
366366
ERROR: cannot use system column "xmin" in partition key
367+
-- cannot use pseudotypes
368+
CREATE TABLE partitioned (
369+
a int,
370+
b int
371+
) PARTITION BY RANGE (((a, b)));
372+
ERROR: column "partition key" has pseudo-type record
373+
CREATE TABLE partitioned (
374+
a int,
375+
b int
376+
) PARTITION BY RANGE (a, ('unknown'));
377+
ERROR: column "partition key" has pseudo-type unknown
367378
-- functions in key must be immutable
368379
CREATE FUNCTION immut_func (a int) RETURNS int AS $$ SELECT a + random()::int; $$ LANGUAGE SQL;
369380
CREATE TABLE partitioned (

‎src/test/regress/sql/create_table.sql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ CREATE TABLE partitioned (
345345

346346
CREATETABLEpartitioned (
347347
aint
348-
) PARTITION BY RANGE (('a'));
348+
) PARTITION BY RANGE ((42));
349349

350350
CREATEFUNCTIONconst_func () RETURNSintAS $$SELECT1; $$ LANGUAGE SQL IMMUTABLE;
351351
CREATETABLEpartitioned (
@@ -368,6 +368,16 @@ CREATE TABLE partitioned (
368368
aint
369369
) PARTITION BY RANGE (xmin);
370370

371+
-- cannot use pseudotypes
372+
CREATETABLEpartitioned (
373+
aint,
374+
bint
375+
) PARTITION BY RANGE (((a, b)));
376+
CREATETABLEpartitioned (
377+
aint,
378+
bint
379+
) PARTITION BY RANGE (a, ('unknown'));
380+
371381
-- functions in key must be immutable
372382
CREATEFUNCTIONimmut_func (aint) RETURNSintAS $$SELECT a+ random()::int; $$ LANGUAGE SQL;
373383
CREATETABLEpartitioned (

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp