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

Commitb434951

Browse files
committed
Fix a thinko in my patch of a couple months ago for bug #3116: it did the
wrong thing when inlining polymorphic SQL functions, because it was using thefunction's declared return type where it should have used the actual resulttype of the current call. In 8.1 and 8.2 this causes obvious failures even ifyou don't have assertions turned on; in 8.0 and 7.4 it would only be a problemif the inlined expression were used as an input to a function that didrun-time type determination on its inputs. Add a regression test, since thisis evidently an under-tested area.
1 parentc432061 commitb434951

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

‎src/backend/optimizer/util/clauses.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.243 2007/04/30 00:14:54 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.244 2007/05/01 18:53:51 tgl Exp $
1212
*
1313
* HISTORY
1414
* AUTHORDATEMAJOR EVENT
@@ -3063,11 +3063,11 @@ inline_function(Oid funcid, Oid result_type, List *args,
30633063
* compatible with the original expression result type. To avoid
30643064
* confusing matters, insert a RelabelType in such cases.
30653065
*/
3066-
if (exprType(newexpr)!=funcform->prorettype)
3066+
if (exprType(newexpr)!=result_type)
30673067
{
3068-
Assert(IsBinaryCoercible(exprType(newexpr),funcform->prorettype));
3068+
Assert(IsBinaryCoercible(exprType(newexpr),result_type));
30693069
newexpr= (Node*)makeRelabelType((Expr*)newexpr,
3070-
funcform->prorettype,
3070+
result_type,
30713071
-1,
30723072
COERCE_IMPLICIT_CAST);
30733073
}

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,3 +542,38 @@ select mysum2(f1, f1 + 1) from t;
542542
38
543543
(1 row)
544544

545+
-- test inlining of polymorphic SQL functions
546+
create function bleat(int) returns int as $$
547+
begin
548+
raise notice 'bleat %', $1;
549+
return $1;
550+
end$$ language plpgsql;
551+
create function sql_if(bool, anyelement, anyelement) returns anyelement as $$
552+
select case when $1 then $2 else $3 end $$ language sql;
553+
-- Note this would fail with integer overflow, never mind wrong bleat() output,
554+
-- if the CASE expression were not successfully inlined
555+
select f1, sql_if(f1 > 0, bleat(f1), bleat(f1 + 1)) from int4_tbl;
556+
NOTICE: bleat 1
557+
NOTICE: bleat 123456
558+
NOTICE: bleat -123455
559+
NOTICE: bleat 2147483647
560+
NOTICE: bleat -2147483646
561+
f1 | sql_if
562+
-------------+-------------
563+
0 | 1
564+
123456 | 123456
565+
-123456 | -123455
566+
2147483647 | 2147483647
567+
-2147483647 | -2147483646
568+
(5 rows)
569+
570+
select q2, sql_if(q2 > 0, q2, q2 + 1) from int8_tbl;
571+
q2 | sql_if
572+
-------------------+-------------------
573+
456 | 456
574+
4567890123456789 | 4567890123456789
575+
123 | 123
576+
4567890123456789 | 4567890123456789
577+
-4567890123456789 | -4567890123456788
578+
(5 rows)
579+

‎src/test/regress/sql/polymorphism.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,19 @@ select f3, myaggn08b(f1) from t group by f3;
374374
select f3, myaggn09a(f1)from tgroup by f3;
375375
select f3, myaggn10a(f1)from tgroup by f3;
376376
select mysum2(f1, f1+1)from t;
377+
378+
-- test inlining of polymorphic SQL functions
379+
createfunctionbleat(int) returnsintas $$
380+
begin
381+
raise notice'bleat %', $1;
382+
return $1;
383+
end$$ language plpgsql;
384+
385+
createfunctionsql_if(bool, anyelement, anyelement) returns anyelementas $$
386+
select case when $1 then $2 else $3 end $$ language sql;
387+
388+
-- Note this would fail with integer overflow, never mind wrong bleat() output,
389+
-- if the CASE expression were not successfully inlined
390+
select f1, sql_if(f1>0, bleat(f1), bleat(f1+1))from int4_tbl;
391+
392+
select q2, sql_if(q2>0, q2, q2+1)from int8_tbl;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp