Re: SQLFunctionCache and generic plans
Alexander Law <exclusion@gmail.com>
From: Alexander Lakhin <exclusion@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Alexander Pyhalov <a.pyhalov@postgrespro.ru>,
Pavel Stehule <pavel.stehule@gmail.com>,
Alexander Korotkov <aekorotkov@gmail.com>,
pgsql-hackers@lists.postgresql.org, Ronan Dunklau <ronan.dunklau@aiven.io>
Date: 2025-04-04T19:00:01Z
Lists: pgsql-hackers
Hello Tom, 03.04.2025 22:13, Tom Lane wrpte: > Drat. I thought I'd tested the empty-function-body case, but > evidently that was a few changes too far back. Will fix, > thanks for catching it. I've stumbled upon another defect introduced with 0dca5d68d: CREATE FUNCTION f(VARIADIC ANYARRAY) RETURNS ANYELEMENT AS $$ SELECT x FROM generate_series(1,1) g(i) $$ LANGUAGE SQL IMMUTABLE; SELECT f(1); SELECT f(1); fails under Valgrind with: 2025-04-04 18:31:13.771 UTC [242811] LOG: statement: SELECT f(1); ==00:00:00:19.324 242811== Invalid read of size 4 ==00:00:00:19.324 242811== at 0x48D610: copyObjectImpl (copyfuncs.c:187) ==00:00:00:19.324 242811== by 0x490194: _copyAlias (copyfuncs.funcs.c:48) ==00:00:00:19.324 242811== by 0x48D636: copyObjectImpl (copyfuncs.switch.c:19) ==00:00:00:19.324 242811== by 0x491CBF: _copyRangeFunction (copyfuncs.funcs.c:1279) ==00:00:00:19.324 242811== by 0x48DC9C: copyObjectImpl (copyfuncs.switch.c:271) ==00:00:00:19.324 242811== by 0x4A295C: list_copy_deep (list.c:1652) ==00:00:00:19.324 242811== by 0x4900FA: copyObjectImpl (copyfuncs.c:192) ==00:00:00:19.324 242811== by 0x4931E4: _copySelectStmt (copyfuncs.funcs.c:2109) ==00:00:00:19.324 242811== by 0x48E00C: copyObjectImpl (copyfuncs.switch.c:436) ==00:00:00:19.324 242811== by 0x492F85: _copyRawStmt (copyfuncs.funcs.c:2026) ==00:00:00:19.324 242811== by 0x48DFBC: copyObjectImpl (copyfuncs.switch.c:421) ==00:00:00:19.324 242811== by 0x76DCCE: CreateCachedPlan (plancache.c:213) ==00:00:00:19.324 242811== Address 0x11b478d0 is 4,032 bytes inside a block of size 8,192 alloc'd ==00:00:00:19.324 242811== at 0x4846828: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so) ==00:00:00:19.324 242811== by 0x7AA15D: AllocSetContextCreateInternal (aset.c:444) ==00:00:00:19.324 242811== by 0x43CF56: init_sql_fcache (functions.c:616) ==00:00:00:19.324 242811== by 0x43CF56: fmgr_sql (functions.c:1484) ==00:00:00:19.324 242811== by 0x423E13: ExecInterpExpr (execExprInterp.c:926) ==00:00:00:19.324 242811== by 0x41EB54: ExecInterpExprStillValid (execExprInterp.c:2299) ... Best regards, Alexander Lakhin Neon (https://neon.tech)
Commits
-
Fix performance issue in deadlock-parallel isolation test.
- 837cc73af29c 18.0 landed
-
functions.c: copy trees from source_list before parse analysis etc.
- 0f43083d16f4 18.0 landed
-
Fix oversight in commit 0dca5d68d.
- dbd437e670b8 18.0 landed
-
Change SQL-language functions to use the plan cache.
- 0dca5d68d7be 18.0 landed
-
Reordering DISTINCT keys to match input path's pathkeys
- a8ccf4e93a7e 18.0 cited