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

Commit0a9ae18

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 parent35d1eef commit0a9ae18

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
@@ -4037,6 +4037,30 @@ transformPartitionBoundValue(ParseState *pstate, Node *val,
40374037
{
40384038
OidexprCollOid=exprCollation(value);
40394039

4040+
/*
4041+
* Check we have a collation iff it is a collatable type. The only
4042+
* expected failures here are (1) COLLATE applied to a noncollatable
4043+
* type, or (2) partition bound expression had an unresolved
4044+
* collation. But we might as well code this to be a complete
4045+
* consistency check.
4046+
*/
4047+
if (type_is_collatable(colType))
4048+
{
4049+
if (!OidIsValid(exprCollOid))
4050+
ereport(ERROR,
4051+
(errcode(ERRCODE_INDETERMINATE_COLLATION),
4052+
errmsg("could not determine which collation to use for partition bound expression"),
4053+
errhint("Use the COLLATE clause to set the collation explicitly.")));
4054+
}
4055+
else
4056+
{
4057+
if (OidIsValid(exprCollOid))
4058+
ereport(ERROR,
4059+
(errcode(ERRCODE_DATATYPE_MISMATCH),
4060+
errmsg("collations are not supported by type %s",
4061+
format_type_be(colType))));
4062+
}
4063+
40404064
if (OidIsValid(exprCollOid)&&
40414065
exprCollOid!=DEFAULT_COLLATION_OID&&
40424066
exprCollOid!=partCollation)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,12 @@ CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (genera
603603
ERROR: set-returning functions are not allowed in partition bound
604604
LINE 1: ...expr_fail PARTITION OF list_parted FOR VALUES IN (generate_s...
605605
^
606+
CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN ('1' collate "POSIX");
607+
ERROR: collations are not supported by type integer
608+
CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN ((1+1) collate "POSIX");
609+
ERROR: collations are not supported by type integer
610+
LINE 1: ...ail PARTITION OF list_parted FOR VALUES IN ((1+1) collate "P...
611+
^
606612
-- syntax does not allow empty list of values for list partitions
607613
CREATE TABLE fail_part PARTITION OF list_parted FOR VALUES IN ();
608614
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
@@ -516,6 +516,8 @@ CREATE TABLE part_bogus_expr_fail PARTITION OF list_parted FOR VALUES IN (sum(so
516516
CREATETABLEpart_bogus_expr_fail PARTITION OF list_parted FORVALUESIN (sum(1));
517517
CREATETABLEpart_bogus_expr_fail PARTITION OF list_parted FORVALUESIN ((select1));
518518
CREATETABLEpart_bogus_expr_fail PARTITION OF list_parted FORVALUESIN (generate_series(4,6));
519+
CREATETABLEpart_bogus_expr_fail PARTITION OF list_parted FORVALUESIN ('1' collate"POSIX");
520+
CREATETABLEpart_bogus_expr_fail PARTITION OF list_parted FORVALUESIN ((1+1) collate"POSIX");
519521

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp