Subject | RDB$GET_CONTEXT performance vs PK lookup query |
---|---|
Author | |
Post date | 2014-06-19T03:11:05Z |
Hello Group,
I am looking at a situation where lots of different stored procedures need to execute an alternate query where a certain condition is true in the database.
I would normally do something along the lines
IF (EXISTS(SELECT 1 FROM CONFIG WHERE CONFIGID = 1234 AND VALUE=1)) THEN
BEGIN
-- Do alternate query
END
ELSE
BEGIN
-- Do usual query
END
-- Do alternate query
END
ELSE
BEGIN
-- Do usual query
END
I should note that the flag I am talking about is static for the duration of these connections, so there is no logical difference in this behaviour.
I am looking at a situation where lots of different stored procedures need to execute an alternate query where a certain condition is true in the database.
I would normally do something along the lines
IF (EXISTS(SELECT 1 FROM CONFIG WHERE CONFIGID = 1234 AND VALUE=1)) THEN
BEGIN
-- Do alternate query
END
ELSE
BEGIN
-- Do usual query
END
ConfigID is a primary key, so it is already quite efficient, but I am interested in whether it is even more efficient if I was to use RDB$GET_CONTEXT.
For example, when I establish the connection, I could do something like
IF (EXISTS(SELECT 1 FROM CONFIG WHERE CONFIGID = 1234 AND VALUE=1)) THEN
BEGIN
rdb$set_context('USER_SESSION', 'Config1234', '1');
END
And then I can refer in my various stored procedures
IF ((RDB$GET_CONTEXT('USER_SESSION', 'Config1234')=1) THEN
BEGIN-- Do alternate query
END
ELSE
BEGIN
-- Do usual query
END
I should note that the flag I am talking about is static for the duration of these connections, so there is no logical difference in this behaviour.
So my question is whether there would be any possible improvement in performance from this (or whether for example the context variables are internally stored in a table anyway and so it is at best the same)?
Thanks
Adam