Re: Dynamic SQL using parameter markers vs. embedded SQL using host variables
Patrik Schindler <[email protected]>
| Newsgroups | gmane.comp.lang.as400.rpg |
|---|---|
| Message-ID | <[email protected]> |
Hello Dan, Am 11.09.2025 um 23:13 schrieb Dan Bale <dan.bale-EkiVQpMPPJH8R359/[email protected]>: > We have a lot of embedded SQL that uses host variables, e.g.: > Select a, b, c from custmast where c = :hostc; > > It has been suggested to me that this can cause performance issues because the plan cache may need to be "rebuilt"(?), so we should consider replacing these type of queries with dynamic SQL using parameter markers, e.g. > > SQLStatement = 'Select a, b, c from custmast where c = ?'; > Exec SQL Prepare P1 from :SQLStatement; > Exec SQL Declare C1 cursor for P1; > Exec SQL Open C1 USING :hostc; > > Is anyone aware of a resource that describes this in detail? I can't elaborate about embedded SQL, but I'm also using parameter markers when I access my machine via ODBC from Perl scripts. Instead of immediately executing a request, I'm just preparing it for later repeated execution, as per your example. Syntax is somewhat different, though. When using this feature, the OS creates *SQLPKG objects, probably as cache? > Maybe also provide test cases that prove performance gains? (Or not?) I have no precise numbers, but I presume that the number of raw inserts per second into tables on my venerable model 150 increased about tenfold. That was a good thing to learn about, and rewrite the code accordingly. I don't remember performance gains in selects, but that's probably because the transition period between just using ODBC as I knew it from MySQL, and adopting prepared statements was rather brief. Some days, maximum. Not much to offer here, but maybe it gives you an idea. :wq! PoC -- This is the RPG programming on IBM i (RPG400-L) mailing list To post a message email: [email protected] To subscribe, unsubscribe, or change list options, visit: https://lists.midrange.com/mailman/listinfo/rpg400-l or email: RPG400-L-request-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org Before posting, please take a moment to review the archives at https://archive.midrange.com/rpg400-l. Please contact support-FMtJrHiV//lnDLsaKlm4mFaTQe2KTcn/@public.gmane.org for any subscription related questions.