public inbox for [email protected]
help / color / mirror / Atom feedFrom: =?ISO-8859-1?B?emVuZ21hbg==?= <[email protected]>
To: =?ISO-8859-1?B?UGF2ZWwgU3RlaHVsZQ==?= <[email protected]>
To: =?ISO-8859-1?B?VG9tIExhbmU=?= <[email protected]>
Cc: =?ISO-8859-1?B?cGdzcWwtaGFja2Vycw==?= <[email protected]>
Subject: Re: Inline non-SQL SRFs using SupportRequestSimplify
Date: Sat, 20 Dec 2025 12:23:41 +0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAFj8pRAH17WO_d9nUWAsV8MXVAVC18Jmn7f+KxGfakEHFY33Xg@mail.gmail.com>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<CA+renyXxanvX8rnrqTNkZt1r9=rm59MHSG4DDVfsV2aUGe3dUQ@mail.gmail.com>
<[email protected]>
<CAFj8pRAH17WO_d9nUWAsV8MXVAVC18Jmn7f+KxGfakEHFY33Xg@mail.gmail.com>
Hi everyone,
I've noticed this interesting feature and would like to modify this test case to clarify that we fall back to the original logic when inlining fails.
This is a small change that doesn't touch core code. What do you all think?
Regards
Man Zeng
Attachments:
[application/octet-stream] 0001-misc_functions-Verify-Function-Scan-fallback-on-inli.patch (3.7K, ../[email protected]/2-0001-misc_functions-Verify-Function-Scan-fallback-on-inli.patch)
download | inline diff:
From 3b55e316c45a1f309864b384d147bd85c19a9579 Mon Sep 17 00:00:00 2001
From: Man Zeng <[email protected]>
Date: Sat, 20 Dec 2025 12:09:07 +0800
Subject: [PATCH] misc_functions: Verify Function Scan fallback on inline
failure
Execution plan falls back to Function Scan (run original PL/pgSQL logic) when inlining fails
Signed-off-by: Man Zeng <[email protected]>
---
src/test/regress/expected/misc_functions.out | 21 +++++++++++++++++++-
src/test/regress/sql/misc_functions.sql | 8 +++++++-
2 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/src/test/regress/expected/misc_functions.out b/src/test/regress/expected/misc_functions.out
index d7d965d884a..212de3e2783 100644
--- a/src/test/regress/expected/misc_functions.out
+++ b/src/test/regress/expected/misc_functions.out
@@ -815,13 +815,17 @@ CREATE FUNCTION test_inline_in_from_support_func(internal)
RETURNS internal
AS :'regresslib', 'test_inline_in_from_support_func'
LANGUAGE C STRICT;
-CREATE FUNCTION foo_from_bar(colname TEXT, tablename TEXT, filter TEXT)
+CREATE FUNCTION foo_from_bar(colname TEXT DEFAULT NULL, tablename TEXT DEFAULT NULL, filter TEXT DEFAULT NULL)
RETURNS SETOF TEXT
LANGUAGE plpgsql
AS $function$
DECLARE
sql TEXT;
BEGIN
+ IF tablename IS NULL AND colname IS NULL THEN
+ tablename = 'text_tbl';
+ colname = 'f1';
+ END IF;
sql := format('SELECT %I::text FROM %I', colname, tablename);
IF filter IS NOT NULL THEN
sql := CONCAT(sql, format(' WHERE %I::text = $1', colname));
@@ -844,6 +848,14 @@ SELECT * FROM foo_from_bar('f1', 'text_tbl', 'doh!');
doh!
(1 row)
+SELECT * FROM foo_from_bar();
+WARNING: test_inline_in_from_support_func called with non-TEXT parameters
+ foo_from_bar
+-------------------
+ doh!
+ hi de ho neighbor
+(2 rows)
+
EXPLAIN (COSTS OFF) SELECT * FROM foo_from_bar('f1', 'text_tbl', NULL);
QUERY PLAN
----------------------
@@ -857,6 +869,13 @@ EXPLAIN (COSTS OFF) SELECT * FROM foo_from_bar('f1', 'text_tbl', 'doh!');
Filter: (f1 = 'doh!'::text)
(2 rows)
+EXPLAIN (COSTS OFF) SELECT * FROM foo_from_bar();
+WARNING: test_inline_in_from_support_func called with non-TEXT parameters
+ QUERY PLAN
+-------------------------------
+ Function Scan on foo_from_bar
+(1 row)
+
DROP FUNCTION foo_from_bar;
-- Test functions for control data
SELECT count(*) > 0 AS ok FROM pg_control_checkpoint();
diff --git a/src/test/regress/sql/misc_functions.sql b/src/test/regress/sql/misc_functions.sql
index 0fc20fbb6b4..a4078ee3dfc 100644
--- a/src/test/regress/sql/misc_functions.sql
+++ b/src/test/regress/sql/misc_functions.sql
@@ -369,13 +369,17 @@ CREATE FUNCTION test_inline_in_from_support_func(internal)
AS :'regresslib', 'test_inline_in_from_support_func'
LANGUAGE C STRICT;
-CREATE FUNCTION foo_from_bar(colname TEXT, tablename TEXT, filter TEXT)
+CREATE FUNCTION foo_from_bar(colname TEXT DEFAULT NULL, tablename TEXT DEFAULT NULL, filter TEXT DEFAULT NULL)
RETURNS SETOF TEXT
LANGUAGE plpgsql
AS $function$
DECLARE
sql TEXT;
BEGIN
+ IF tablename IS NULL AND colname IS NULL THEN
+ tablename = 'text_tbl';
+ colname = 'f1';
+ END IF;
sql := format('SELECT %I::text FROM %I', colname, tablename);
IF filter IS NOT NULL THEN
sql := CONCAT(sql, format(' WHERE %I::text = $1', colname));
@@ -389,8 +393,10 @@ ALTER FUNCTION foo_from_bar(TEXT, TEXT, TEXT)
SELECT * FROM foo_from_bar('f1', 'text_tbl', NULL);
SELECT * FROM foo_from_bar('f1', 'text_tbl', 'doh!');
+SELECT * FROM foo_from_bar();
EXPLAIN (COSTS OFF) SELECT * FROM foo_from_bar('f1', 'text_tbl', NULL);
EXPLAIN (COSTS OFF) SELECT * FROM foo_from_bar('f1', 'text_tbl', 'doh!');
+EXPLAIN (COSTS OFF) SELECT * FROM foo_from_bar();
DROP FUNCTION foo_from_bar;
--
2.45.2
view thread (19+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: Inline non-SQL SRFs using SupportRequestSimplify
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox