Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am using SQL2005 and against them I calling query simila to this

    declare @art table (id int primary key, naziv varchar(35) null, sifra varchar(15) null, jm int null);   

            insert into @art
            select id, left(naziv,35), left(sifra,15), jm from art a
            where   (a.id = @art_id@ or @art_id@ = 0 )

Select 
      s.art_id
     ,sum(kol) as kol
     ,sum(kol*mpc) as MPCI
     /*--and meny others --/
    from doc d 
                inner join dokumenti dk on (d.tip = dk.tip)
                inner join sdo s on (d.id=s.doc_id)
        where           
                        d.datum between  @do_datuma@ and @do_datuma@
                        and dk.prodaja = 1
                        and (dk.Mal_Vel in (@Mal_Vel@))
                        and (d.skl_id = @skl_id@ or (@skl_id@ = 0))
                        and ((d.skl_id in (select skl_id from skladiste_gruperj  where grp_id = @gr_rj_id@)) or ( @gr_rj_id@ = 0))
                        and (d.par_id = @par_id@ or @par_id@ = 0)
                        and s.art_id in (select id from @art)
            group by s.art_id

This is query is slow when I take look at Execution plan I see that is Cost of 71 % is taken by Key Lookup.

What I can do to seed up this query.

This is how looks like my Execution plan

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Remove it by making the index covering

That is, add an INCLUDE clause to the index so all columns needed are in the index.

share|improve this answer
    
Thank You so mach on fast post and also on all your answers. Which columns I do need to add after clause INCLUDE, Do I need to make Index with INCLUDE all output columns from table or only columns which is in filter (where). –  adopilot Aug 26 '11 at 14:29
    
@adopilot: you'll see what columns when you hover over the key lookup. I can't tell from the picture –  gbn Aug 26 '11 at 14:35
    
@gbn did you try hovering over the picture? –  Derek Downey Aug 26 '11 at 15:13
    
@DTest: no. You hover over the execution plan in SSMS to get the columns. Not a picture of the plan on a webpage... The properties window in the image is chopped off too. How would you get the columns from this image? –  gbn Aug 26 '11 at 15:43
    
I was being tongue-in-cheek. –  Derek Downey Aug 26 '11 at 15:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.