Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic list of parameters for execute statement - performance POV [CORE4813] #5111

Open
firebird-automations opened this issue May 27, 2015 · 4 comments

Comments

@firebird-automations
Copy link
Collaborator

Submitted by: @livius2

Is related to CORE4736

Votes: 2

Will be good to see a way to build dynamic list of parameters for execute statement at procedure run-time
now we have only possibility to specify parameters known at procedure creation time like

EXECUTE STATEMENT (VAR_SQL) (PARAM_X := aaa, PARAM_Y := ....)

but it is impossible to build params list at runtime - which "violates" concept of EXECUTE STATEMENT for dynamically created queries

Will be good to see the way to specify dynamic list of parameters build at run-time.
The concept is in example pseudo-code

SET TERM ^ ;
CREATE PROCEDURE MY_PROC_CALC_EXEC_PARAM(ID INTEGER) RETURNS(SUM_AAA INTEGER)
AS
DECLARE VARIABLE VAR_SQL VARCHAR(1000);
DECLARE VARIABLE VAR_BBB INTEGER;
DECLARE VARIABLE VAR_NR INTEGER;
DECLARE VARIABLE VAR_PARAM_NAME VARCAHR(10);
BEGIN
VAR_SQL = 'SELECT SUM(AAA) FROM TABLEY WHERE ID=:ID ';
VAR_NR = 1;
FOR SELECT
BBB
FROM
TABLEZ
WHERE ID=:ID
INTO :VAR_BBB
DO
BEGIN
/* DO SOME CALCULATION ON VAR_BBB */
VAR_PARAM_NAME = 'ID' || VAR_NR;
VAR_SQL = VAR_SQL || ' OR ID=:' || VAR_PARAM_NAME;

    PARAMS\.ByNAME\[VAR\_PARAM\_NAME\] := VAR\_BBB; <\-\- here we create param in virtual space "PARAMS" \- quite same like NEW\.FIELD, OLD\.FIELD work \- but parameter is created at request not at start of proc
    /\* may be it is also possible for unnamed params \- PARAMS\.ByPosition\[4\] 4 treated as name with internal prefix to prevent allocation of parameters form 1 to 9999 if we specify ByPosition\[9999\] ;\-\)
   \*/
  VAR\_NR = VAR\_NR \+ 1;
END

EXECUTE STATEMENT (VAR_SQL) (PARAMS) <----- Here we specify parameters list
INTO :SUM_AAA;

SUSPEND;
END^
SET TERM ; ^

this feature is important from performance POV and server resources POV for queries like this:

SELECT (SELECT P.SUM_AAA FROM MY_PROC_CALC_EXEC_PARAM(T.FIELD_ID) P) FROM TABLEX T

without parameters, for every record returned from TABLEX, stored procedure is executed and query is prepared
prepare distinct queries for every record is time consuming process
but with parameters this will be very fast only few distinct prepared queries

i compare times for real example
where i put in stored proc execute statement with and without parameters
and for query with 100000 records i got times:
15 sec with parameters
42 sec plain text passed to execute statement - for every record query was prepared by server which consume time

PS.
old form without (PARAMS) should work as previously
like EXECUTE STATEMENT (VAR_SQL) (ID1 := something, ID2:= something)

====== Test Details ======

See test for CORE5658

@firebird-automations
Copy link
Collaborator Author

Modified by: @livius2

Component: Engine [ 10000 ]

@firebird-automations
Copy link
Collaborator Author

Commented by: Omacht András (aomacht)

Please link this issue to CORE4736. Thanks.
(CORE4736)

@firebird-automations
Copy link
Collaborator Author

Modified by: @dyemanov

Link: This issue is related to CORE4736 [ CORE4736 ]

@firebird-automations
Copy link
Collaborator Author

Modified by: @pavel-zotov

status: Open [ 1 ] => Open [ 1 ]

QA Status: No test => Covered by another test(s)

Test Details: See test for CORE5658

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant