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

Commit281dd22

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 parent31dfa40 commit281dd22

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
@@ -14402,6 +14402,16 @@ ComputePartitionAttrs(Relation rel, List *partParams, AttrNumber *partattrs,
1440214402
atttype=exprType(expr);
1440314403
attcollation=exprCollation(expr);
1440414404

14405+
/*
14406+
* The expression must be of a storable type (e.g., not RECORD).
14407+
* The test is the same as for whether a table column is of a safe
14408+
* type (which is why we needn't check for the non-expression
14409+
* case).
14410+
*/
14411+
CheckAttributeType("partition key",
14412+
atttype,attcollation,
14413+
NIL, false);
14414+
1440514415
/*
1440614416
* Strip any top-level COLLATE clause. This ensures that we treat
1440714417
* "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
@@ -334,7 +334,7 @@ CREATE TABLE partitioned (
334334
ERROR: cannot use subquery in partition key expression
335335
CREATE TABLE partitioned (
336336
a int
337-
) PARTITION BY RANGE (('a'));
337+
) PARTITION BY RANGE ((42));
338338
ERROR: cannot use constant expression as partition key
339339
CREATE FUNCTION const_func () RETURNS int AS $$ SELECT 1; $$ LANGUAGE SQL IMMUTABLE;
340340
CREATE TABLE partitioned (
@@ -357,6 +357,17 @@ CREATE TABLE partitioned (
357357
a int
358358
) PARTITION BY RANGE (xmin);
359359
ERROR: cannot use system column "xmin" in partition key
360+
-- cannot use pseudotypes
361+
CREATE TABLE partitioned (
362+
a int,
363+
b int
364+
) PARTITION BY RANGE (((a, b)));
365+
ERROR: column "partition key" has pseudo-type record
366+
CREATE TABLE partitioned (
367+
a int,
368+
b int
369+
) PARTITION BY RANGE (a, ('unknown'));
370+
ERROR: column "partition key" has pseudo-type unknown
360371
-- functions in key must be immutable
361372
CREATE FUNCTION immut_func (a int) RETURNS int AS $$ SELECT a + random()::int; $$ LANGUAGE SQL;
362373
CREATE TABLE partitioned (

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

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

344344
CREATETABLEpartitioned (
345345
aint
346-
) PARTITION BY RANGE (('a'));
346+
) PARTITION BY RANGE ((42));
347347

348348
CREATEFUNCTIONconst_func () RETURNSintAS $$SELECT1; $$ LANGUAGE SQL IMMUTABLE;
349349
CREATETABLEpartitioned (
@@ -366,6 +366,16 @@ CREATE TABLE partitioned (
366366
aint
367367
) PARTITION BY RANGE (xmin);
368368

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp