Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Indexing help

Author  Topic 

meef
Posting Yak Master

113 Posts

Posted - 2011-09-26 : 14:53:13
I'll use this FROM section as an example:

FROM    tbl_bol tb
LEFT JOIN dbo.tbl_ref_nums u on tb.bol_id = u.bol_id
INNER JOIN dbo.tbl_214_datatable p on tb.bol_id = p.bol_id
INNER JOIN tbl_carrier c ON c.scac_code = p.scac
INNER JOIN tbl_carrier_access a ON a.carrier_id = c.carrier_id AND a.dba_id = tb.dba_id


I think you're supposed to index on the columns that you are matching to, not the ones you're joining from, is that correct? Does that mean index on columns after the "ON" portion?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-26 : 14:58:45
usually you create index on joining columns. didnt understand what you're asking actually

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

meef
Posting Yak Master

113 Posts

Posted - 2011-09-26 : 14:59:50
Going by the sample I posted above, can you tell which ones would need to be indexed?

EDIT: I was guessing these are the ones to index on:

bol_id
scac_code
carrier_id
dba_id

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-09-26 : 15:20:59
All of them should be indexed. Here they are:

tb.bol_id
u.bol_id
p.bol_id
c.scac_code
p.scac
a.carrier_id
c.carrier_id
a.dba_id
tb.dba_id

For table aliased as a, you may want to just use a composite index of carrier_id,dba_id.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-09-26 : 16:28:50
For the table p, you probably want a composite index either (bol_id, scac) or (scac, bol_id). Test to see which works better. Or add both
For the table c, either (scac_code, carrier_id) or (carrier_id, scac_code). Same as above.
Same thing with tb

--
Gail Shaw
SQL Server MVP
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2011-09-26 : 17:48:54
Might want some INCLUDE columns to in order to "cover" other columns used in the query - SELECT columns, etc.
Go to Top of Page
   

- Advertisement -