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

Commit6c7251d

Browse files
committed
Implement new optimization rule for updates of expanded variables.
If a read/write expanded variable is declared locally to theassignment statement that is updating it, and it is referencedexactly once in the assignment RHS, then we can optimize theoperation as a direct update of the expanded value, whetheror not the function(s) operating on it can be trusted not tomodify the value before throwing an error. This works becauseif an error does get thrown, we no longer care what value thevariable has.In cases where that doesn't work, fall back to the previousrule that checks for safety of the top-level function.In any case, postpone determination of whether these optimizationsare feasible until we are executing a Param referencing the targetvariable and that variable holds a R/W expanded object. While theprevious incarnation of exec_check_rw_parameter was pretty cheap,this is a bit less so, and our plan to invoke support functionswill make it even less so. So avoiding the check for variableswhere it couldn't be useful should be a win.Author: Tom Lane <tgl@sss.pgh.pa.us>Reviewed-by: Andrey Borodin <x4mmm@yandex-team.ru>Reviewed-by: Pavel Borisov <pashkin.elfe@gmail.com>Discussion:https://postgr.es/m/CACxu=vJaKFNsYxooSnW1wEgsAO5u_v1XYBacfVJ14wgJV_PYeg@mail.gmail.com
1 parent36fb9ef commit6c7251d

File tree

6 files changed

+364
-62
lines changed

6 files changed

+364
-62
lines changed

‎src/include/executor/execExpr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ typedef struct ExprEvalStep
425425
{
426426
ExecEvalSubroutineparamfunc;/* add-on evaluation subroutine */
427427
void*paramarg;/* private data for same */
428+
void*paramarg2;/* more private data for same */
428429
intparamid;/* numeric ID for parameter */
429430
Oidparamtype;/* OID of parameter's datatype */
430431
}cparam;

‎src/pl/plpgsql/src/expected/plpgsql_array.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ NOTICE: a = ("{""(,11)""}",), a.c1[1].i = 11
5252
do $$ declare a int[];
5353
begin a := array_agg(x) from (values(1),(2),(3)) v(x); raise notice 'a = %', a; end$$;
5454
NOTICE: a = {1,2,3}
55+
do $$ declare a int[] := array[1,2,3];
56+
begin
57+
-- test scenarios for optimization of updates of R/W expanded objects
58+
a := array_append(a, 42); -- optimizable using "transfer" method
59+
a := a || a[3]; -- optimizable using "inplace" method
60+
a := a || a; -- not optimizable
61+
raise notice 'a = %', a;
62+
end$$;
63+
NOTICE: a = {1,2,3,42,3,1,2,3,42,3}
5564
create temp table onecol as select array[1,2] as f1;
5665
do $$ declare a int[];
5766
begin a := f1 from onecol; raise notice 'a = %', a; end$$;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp