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

Commitc018786

Browse files
committed
Fix crash when using COLLATE in partition bound expressions
Attempting to use a COLLATE clause with a type that it not collatable ina partition bound expression could crash the server. This commit fixesthe code by adding more checks similar to what is done when computingindex or partition attributes by making sure that there is a collationiff the type is collatable.Backpatch down to 12, as7c079d7 introduced this problem.Reported-by: Alexander LakhinAuthor: Dmitry DolgovDiscussion:https://postgr.es/m/16325-809194cf742313ab@postgresql.orgBackpatch-through: 12
1 parentd025cf8 commitc018786

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

‎src/backend/parser/parse_utilcmd.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4081,6 +4081,30 @@ transformPartitionBoundValue(ParseState *pstate, Node *val,
40814081
{
40824082
OidexprCollOid=exprCollation(value);
40834083

4084+
/*
4085+
* Check we have a collation iff it is a collatable type. The only
4086+
* expected failures here are (1) COLLATE applied to a noncollatable
4087+
* type, or (2) partition bound expression had an unresolved
4088+
* collation. But we might as well code this to be a complete
4089+
* consistency check.
4090+
*/
4091+
if (type_is_collatable(colType))
4092+
{
4093+
if (!OidIsValid(exprCollOid))
4094+
ereport(ERROR,
4095+
(errcode(ERRCODE_INDETERMINATE_COLLATION),
4096+
errmsg("could not determine which collation to use for partition bound expression"),
4097+
errhint("Use the COLLATE clause to set the collation explicitly.")));
4098+
}
4099+
else
4100+
{
4101+
if (OidIsValid(exprCollOid))
4102+
ereport(ERROR,
4103+
(errcode(ERRCODE_DATATYPE_MISMATCH),
4104+
errmsg("collations are not supported by type %s",
4105+
format_type_be(colType))));
4106+
}
4107+
40844108
if (OidIsValid(exprCollOid)&&
40854109
exprCollOid!=DEFAULT_COLLATION_OID&&
40864110
exprCollOid!=partCollation)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,12 @@ CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (genera
652652
ERROR: set-returning functions are not allowed in partition bound
653653
LINE 1: ...expr_fail PARTITION OF list_parted FOR VALUES IN (generate_s...
654654
^
655+
CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN ('1' collate "POSIX");
656+
ERROR: collations are not supported by type integer
657+
CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN ((1+1) collate "POSIX");
658+
ERROR: collations are not supported by type integer
659+
LINE 1: ...ail PARTITION OF list_parted FOR VALUES IN ((1+1) collate "P...
660+
^
655661
-- syntax does not allow empty list of values for list partitions
656662
CREATE TABLE fail_part PARTITION OF list_parted FOR VALUES IN ();
657663
ERROR: syntax error at or near ")"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (sum(so
549549
CREATETABLEpart_bogus_expr_fail PARTITION OF list_parted FORVALUESIN (sum(1));
550550
CREATETABLEpart_bogus_expr_fail PARTITION OF list_parted FORVALUESIN ((select1));
551551
CREATETABLEpart_bogus_expr_fail PARTITION OF list_parted FORVALUESIN (generate_series(4,6));
552+
CREATETABLEpart_bogus_expr_fail PARTITION OF list_parted FORVALUESIN ('1' collate"POSIX");
553+
CREATETABLEpart_bogus_expr_fail PARTITION OF list_parted FORVALUESIN ((1+1) collate"POSIX");
552554

553555
-- syntax does not allow empty list of values for list partitions
554556
CREATETABLEfail_part PARTITION OF list_parted FORVALUESIN ();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp