1

Topic: As sql compiles and stores the plan if it is a lot of if and as influences return

In procedure a little if, but without else.
Go successively.

if @flag = 1
begin
end;
if @flag = 2
begin
end;
if @flag = 3
begin
end;

As the compiler in this case behaves: if to specify in each unit return if not to specify.

2

Re: As sql compiles and stores the plan if it is a lot of if and as influences return

_ _;
Compiles as all
To look to you was faster than to write...

3

Re: As sql compiles and stores the plan if it is a lot of if and as influences return

_ _;

wrote:

As the compiler

in this case behaves
Breaks to Gelendzhik on .
IF without ELSE - a shot and in a foot and in a compiler brain. Then sit, assort, whether these units after the previous can be caused.
If somewhere something to specify, it will be compiled with instructions of the specified. If not to specify something - it does not get to the compiled result therefore as does not exist. In search of mystical optimization it is possible to think on a subject under what @flag the compiler makes the plan. In compile time a variable what value has? And in runtime?

4

Re: As sql compiles and stores the plan if it is a lot of if and as influences return

If to specify in everyone;
Not clearly that for delirium you write, but in  plans there will be even a piece

if 1 = 3
begin
SELECT top 1 * FROM master. spt_values
RETURN
end;

5

Re: As sql compiles and stores the plan if it is a lot of if and as influences return

TaPaK wrote:

if to specify in everyone;
Not clearly that for delirium you write, but in  plans there will be even a piece

if 1 = 3
begin
SELECT top 1 * FROM master. spt_values
RETURN
end;

I here too did not understand, to whom this flow of consciousness is turned. Did not understand that is written - with what argue, and?

6

Re: As sql compiles and stores the plan if it is a lot of if and as influences return

The compiler simply compiles as is. And here the plan will be constructed for that flag with which will be the first procedure call.
Actually at compilation there will be an implicit output after hit in any satisfying if or the check cycle ends last if?

7

Re: As sql compiles and stores the plan if it is a lot of if and as influences return

Better to say, whether builds the compiler a tree of calls leaning on controlling if and whether does superfluous iterations of check or not.
As a matter of fact in it a question.
Not absolutely it about the execution plan. Though concerns it.

8

Re: As sql compiles and stores the plan if it is a lot of if and as influences return

That I mean - the compiler could build how to transit on units and what to do after.
Here would be after all if  like return.
And in this case in a tree of calls (instructions) there could be a following: here into this unit we come, then it is so much that units (if) this where return costs is passed and caused here.

9

Re: As sql compiles and stores the plan if it is a lot of if and as influences return

__;
At you the idle question, or is problems any?

10

Re: As sql compiles and stores the plan if it is a lot of if and as influences return

[quote = _ _] That I mean Promeshan - the compiler could build how to transit on units and what to do after.
Here would be after all if  like return.
And in this case in a tree of calls (instructions) there could be a following: here into this unit we come, then it is so much that units (if) this where return costs is passed and caused here.

It will be the actual plan