From: DAVID ROTH <adaptron@comcast.net>
To: Postgres General <pgsql-general@postgresql.org>
Subject: General Performance Question
Date: Thu, 18 Nov 2021 09:15:13 -0500 (EST)
Message-ID: <1653563957.563818.1637244913291@connect.xfinity.com> (raw)
In-Reply-To: <CAFj8pRDR3E7KNe0tiGekH6wQQ06fBs9E6K3r0h=oTU4FbGMbgA@mail.gmail.com>
References: <CAEKkz87s6c9BL4s2p3Je_y2iCZy0-2mLdV7_YFJ79iOFvRZdkw@mail.gmail.com>
<CAFj8pRDR3E7KNe0tiGekH6wQQ06fBs9E6K3r0h=oTU4FbGMbgA@mail.gmail.com>
I am working on a large Oracle to Postgres migration.
The existing code frequently constructs a string and then uses Oracle's "EXECUTE IMMEDIATE" to run it.
"EXECUTE" has the same functionality in Postgres.
For example:
CREATE or REPLACE FUNCTION djr_foo_fnc (p_emp_no IN number)
RETURN VARCHAR2
AS
v_sql VARCHAR2(1000);
v_name VARCHAR2(30);
BEGIN
v_sql := 'SELECT name FROM employees';
v_sql := v_sql ||' WHERE employee_number = '||p_emp_no;
EXECUTE IMMEDIATE v_sql INTO v_name;
RETURN v_name;
END;
/
CREATE or REPLACE FUNCTION djr_foo_fnc (p_emp_no IN number)
RETURN VARCHAR2
AS
v_name VARCHAR2(30);
BEGIN
SELECT name INTO v_name FROM employees
WHERE employee_number = p_emp_no;
RETURN v_name;
END;
/
These are oversimplified samples of some very complex queries I need to migrate.
How does the Postgres optimizer handle these 2 formats?
Which format is likely to perform better?
Thanks
Dave
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: adaptron@comcast.net
Subject: Re: General Performance Question
In-Reply-To: <1653563957.563818.1637244913291@connect.xfinity.com>
References: <CAEKkz87s6c9BL4s2p3Je_y2iCZy0-2mLdV7_YFJ79iOFvRZdkw@mail.gmail.com> <CAFj8pRDR3E7KNe0tiGekH6wQQ06fBs9E6K3r0h=oTU4FbGMbgA@mail.gmail.com> <1653563957.563818.1637244913291@connect.xfinity.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox