This month (Jan. 2005 p.15) SQL Server Magazine gave a definitive answer to something that I suspected...IF statements within a SP can cause poor performance. Apparently a compiled version of a SP can hold only one query plan, therefore an IF statement that utilizes an input parameter can make it impossible for there to be only one query plan. The article isn't crystal clear to me and dodges the issue of determining which IF statements can cause a problem. It even looks as though the author was intentionally vague, "If SQL Server selects different query plans based on the different branches in the stored procedure..."
The article also hinted at another issue that I've wondered about regarding performance testing, "The downside of breaking the queries into separate stored procedures is that you'll require more memory for the procedure cache because you'll need to hold extra plans in memory..." So SQL Server does keep execution plans (for queries other than SPs???) in memory. That has to play havoc with repeated performance tests. They may get knocked out of the cache.
The same magazine issue (p.13) answers another question bantered about here. The explicit and not so explicit join syntax are both ANSI syntax. And neither ANSI nor Microsoft favors one over the other, however, ANSI discourages the *= syntax which was never adopted by ANSI. (They adopted outer joins in SQL-92 using the From clause to explicitly define the join.) "In fact, SQL Server will produce an incorrect answer if you use the old outer join syntax and include an IS NULL predicate in a column on the dependent side of the join."
-Karl
[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
The article also hinted at another issue that I've wondered about regarding performance testing, "The downside of breaking the queries into separate stored procedures is that you'll require more memory for the procedure cache because you'll need to hold extra plans in memory..." So SQL Server does keep execution plans (for queries other than SPs???) in memory. That has to play havoc with repeated performance tests. They may get knocked out of the cache.
The same magazine issue (p.13) answers another question bantered about here. The explicit and not so explicit join syntax are both ANSI syntax. And neither ANSI nor Microsoft favors one over the other, however, ANSI discourages the *= syntax which was never adopted by ANSI. (They adopted outer joins in SQL-92 using the From clause to explicitly define the join.) "In fact, SQL Server will produce an incorrect answer if you use the old outer join syntax and include an IS NULL predicate in a column on the dependent side of the join."
-Karl
[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]