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

Commit249126e

Browse files
committed
Use context with correct lifetime in hypothetical_dense_rank_final.
The query lifetime expression context created inhypothetical_dense_rank_final() was buggily allocated in the callingmemory context. I (Andres) broke that inbf6c614.Reported-By: Rajkumar RaghuwanshiAuthor: Amit LangoteDiscussion:https://postgr.es/m/CAKcux6kmzWmur5HhA_aU6gYVFu0RLQdgJJ+aC9SLdcOvBSrpfA@mail.gmail.comBackpatch: 11-
1 parent3a01f68 commit249126e

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

‎src/backend/utils/adt/orderedsetaggs.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,15 @@ hypothetical_dense_rank_final(PG_FUNCTION_ARGS)
13101310
osastate= (OSAPerGroupState*)PG_GETARG_POINTER(0);
13111311
econtext=osastate->qstate->econtext;
13121312
if (!econtext)
1313-
osastate->qstate->econtext=econtext=CreateStandaloneExprContext();
1313+
{
1314+
MemoryContextoldcontext;
1315+
1316+
/* Make sure to we create econtext under correct parent context. */
1317+
oldcontext=MemoryContextSwitchTo(osastate->qstate->qcontext);
1318+
osastate->qstate->econtext=CreateStandaloneExprContext();
1319+
econtext=osastate->qstate->econtext;
1320+
MemoryContextSwitchTo(oldcontext);
1321+
}
13141322

13151323
/* Adjust nargs to be the number of direct (or aggregated) args */
13161324
if (nargs %2!=0)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,3 +2092,12 @@ SELECT variance(unique1::int4), sum(unique1::int8) FROM tenk1;
20922092
(1 row)
20932093

20942094
ROLLBACK;
2095+
-- test coverage for dense_rank
2096+
SELECT dense_rank(x) WITHIN GROUP (ORDER BY x) FROM (VALUES (1),(1),(2),(2),(3),(3)) v(x) GROUP BY (x) ORDER BY 1;
2097+
dense_rank
2098+
------------
2099+
1
2100+
1
2101+
1
2102+
(3 rows)
2103+

‎src/test/regress/sql/aggregates.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,3 +925,6 @@ EXPLAIN (COSTS OFF)
925925
SELECT variance(unique1::int4),sum(unique1::int8)FROM tenk1;
926926

927927
ROLLBACK;
928+
929+
-- test coverage for dense_rank
930+
SELECT dense_rank(x) WITHIN GROUP (ORDER BY x)FROM (VALUES (1),(1),(2),(2),(3),(3)) v(x)GROUP BY (x)ORDER BY1;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp