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]>
Cc: =?ISO-8859-1?B?cGdzcWwtaGFja2Vycw==?= <[email protected]>
Cc: =?ISO-8859-1?B?VG9tIExhbmU=?= <[email protected]>
Subject: Re: Inline non-SQL SRFs using SupportRequestSimplify
Date: Sat, 20 Dec 2025 20:21:39 +0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAFj8pRB05eVCRsgTTxzDCtx4G9YLB3D4AKeY7Wp7D6D5gEkP9g@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>
<[email protected]>
<CAFj8pRAF1FjKE=OezxxtmLm6Tc3b+zEzBCQZqLLxdgw5Op-uPw@mail.gmail.com>
<[email protected]>
<CAFj8pRB05eVCRsgTTxzDCtx4G9YLB3D4AKeY7Wp7D6D5gEkP9g@mail.gmail.com>
Thank you for your guidance. Attached is the updated patch.
I wonder if there are any other adjustments needed and look forward to more feedback.
--
Regards
Man Zeng
www.openhalo.org
Attachments:
[application/octet-stream] 0002-misc_functions-Verify-Function-Scan-fallback-on-inli.patch (4.9K, ../[email protected]/2-0002-misc_functions-Verify-Function-Scan-fallback-on-inli.patch)
download | inline diff:
From b7f1ded3512993cb2b71270dd0124af51d2e1936 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 inline fallback & fix TEXT check/warnings
Verify inline failure falls back to Function Scan (original PL/pgSQL logic)
Clean up redundant TEXT check and adjust warnings
Signed-off-by: Man Zeng <[email protected]>
---
src/test/regress/expected/misc_functions.out | 21 +++++++++++++++++++-
src/test/regress/regress.c | 8 ++++----
src/test/regress/sql/misc_functions.sql | 8 +++++++-
3 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/src/test/regress/expected/misc_functions.out b/src/test/regress/expected/misc_functions.out
index d7d965d884a..44e4450cacd 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 null parameter for colname
+ 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 null parameter for colname
+ 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/regress.c b/src/test/regress/regress.c
index b7a926c6f01..adb8b9793ba 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -849,9 +849,9 @@ test_inline_in_from_support_func(PG_FUNCTION_ARGS)
}
c = (Const *) node;
- if (c->consttype != TEXTOID || c->constisnull)
+ if (c->constisnull)
{
- ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-TEXT parameters")));
+ ereport(WARNING, (errmsg("test_inline_in_from_support_func called with null parameter for colname")));
PG_RETURN_POINTER(NULL);
}
colname = TextDatumGetCString(c->constvalue);
@@ -865,9 +865,9 @@ test_inline_in_from_support_func(PG_FUNCTION_ARGS)
}
c = (Const *) node;
- if (c->consttype != TEXTOID || c->constisnull)
+ if (c->constisnull)
{
- ereport(WARNING, (errmsg("test_inline_in_from_support_func called with non-TEXT parameters")));
+ ereport(WARNING, (errmsg("test_inline_in_from_support_func called with null parameter for tablename")));
PG_RETURN_POINTER(NULL);
}
tablename = TextDatumGetCString(c->constvalue);
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