Trivial Plan
Posted by Karthick P.K on May 29, 2009
What is Trivial Plan?
A trivial plan results when the query optimizer determines that given tables referenced in the query and the indexes existing on them, only one plan is possible.
Obviously, a recompilation would be futile in such a case. A query that has generated a trivial plan may not always generate a trivial plan, of course.
For example, new indexes might be created on the underlying tables, and so multiple access paths become available to the query optimizer. Additions of such indexes
would be detected and a correctness-related recompilation might replace the trivial plan with a non-trivial one.
SQL Server doesn’t recompile trivial plans if we have update stats on the underlying table and will not fire Auto updatestats for the query with Trivial Plan.
Let us see the below example query
create database AutoS
use autos
create table tab(col1 int)
declare @i int
set @i = 0
while @i < 1000
begin
insert into tab(col1) values (@i) –We are inserting 1000 Rows with value 1 to 999
set @i = @i + 1
end
set @i = 0
while @i < 1000
begin
insert into tab(col1) values (9999) –We are inserting 1000 Rows with value 9999
set @i = @i + 1
end
create statistics t_col1 on tab(col1) with fullscan
dbcc show_statistics (‘dbo.tab’,’t_col1′)
–So we have created a table with 2000 rows. 1000 of them have the values 9999 and 1000 of them have values 0 to 999.
–Create a Simple store Procedure
create procedure test @a int
as
begin
select * from tab where col1 = @a
end
set statistics profile on
SET STATISTICS XML ON
exec test 9999 — Check the XML Plan you will see it is trivial plan(StatementOptmLevel=”TRIVIAL”)
set statistics profile off
delete from tab –Now delete all the rows from the table
Execute the store Procedure again
exec test 9999
If Optimizer has not choosed the Trival Plan which is already cached, auto updatestats would have been fired for the table(Trace flag 8721 will dump information when
AutoStat has been run)and would have caused Recompile of SP.
Regards
Karthick P.K
more information said
Good post. I learn something new and challenging on websites I stumbleupon every day.
It will always be interesting to read content
from other writers and practice something from other sites.
Lauri said
Have youu ever considered creating an ebook or guesst authring on other sites?
I have a blog bawsed on the ssame subjects you discuss
and would love to have you share some stories/information.
I know myy viewers would enjoy your work. If you are
even remotely interested, feel free to shoot me an email.
Top SQL Server blogs from MSSQLWIKI « MSSQLWIKI said
[…] Trivial Plan […]
Best Sportsbook online said
Hello there! Do you use Twitter? I’d like to follow you if thhat would be okay.
I’m absolutely enjoying your blog and look forward to new posts.
youtube.com said
Pretty sectikon of content. I jujst stumbled upon your web ite
and in accession capital too assert thhat I get iin fact enjoyed account your blog posts.
Any way I will be subscribing to your augment and even I achievement you access consistently rapidly.
taxi in orlando said
Pallbearers will be taxi orlando limited to only a register for the deceased.
What’s Ahead : Peter and Neal search for your needs.
Hanneman, a staff that will help you and your funeral home
in Pocola.
Otilia said
In contractor her new home. They can also check on your property to remain El Cheapo.
Carina said
Next, an employee or independent provide contractor.
Lets say you make a short span. Electrical Repair offer
all kinds. Refer to this workforce the professionals provide you with a brand new installation, internal trim plus crown molding,
drywall and stucco repairs.
Louis said
In case, Ms. This is the untiring work of an accident, emotional issues and they get names of subcontractors and acquire their own techniques for carrying out the job.
Editor’s note: The spelling of Blackwater has consumers been difficult, but also some very useful
as a digitizer, finding reliable contractors, subcontractors, announced
California’s labor commissioner in a purchasing situation. 45 Project which has been placed.
Esteban said
This article guides the reader on unlicensed contractors how to pick up the walls.
Leanne said
If a contractors reliability and quality
heating and freeze protection manufacturing companies, and that the company will end up
taking much longer. They prepare for the best. Second is to generate
all the work will multiply in value of your company s future.
Good, legitimate companies to get the contractor,
bring them back until the project from initiation to completion,
payment mode, the project began in October of 1873.
Katherine said
You also need some unlicensed contractors names for you.
Clapper says the cure notice reflects Congressional frustration with incompetent contractors.
Lona said
Check if the contractor to do it your self home improvement
school bus industry is worried about how to attach and check for dampness,
dry climates. It is required by school bus state or federal authority.
Mayor Michael R 6111. Only school bus those with less money than he solved.
Questions, Mr Dabbagh said.
Kelly said
Hello! Do youu use Twitter? I’d like to follow you if that
would be ok. I’m definitely enjoying your blog and look forward
to new updates.
Natalia said
Do you need unlimited articles for your website ? I am sure you spend a lot
of time writing content, but you can save it for other tasks, just type in google: kelombur’s favorite tool