| Author |
Topic |
|
chriztoph
Posting Yak Master
184 Posts |
Posted - 2010-04-26 : 23:07:38
|
Please help!What's wrong with the query? i got time-out expired..I already Indexed the tables..here is my query:SELECT dbo.tblAdmin_Positions.Position, LTRIM(dbo.tbl_SeamanMain.LastName) AS Lastname, LTRIM(dbo.tbl_SeamanMain.FirstName) AS Firstname, LTRIM(dbo.tbl_SeamanMain.MiddleName) AS Middlename, dbo.tblPayroll_Allottees.AllotteeName, dbo.tblAdmin_Banks.BankName, REPLACE(dbo.tblPayroll_Allottees.AccountNo, '-', '') AS AccountNo, 'PHP' AS AcctCurrency, 0 AS AllotUSD, dbo.tblPayroll_Allottees.NetAllotment AS AllotPHP, dbo.tblPayroll_VesselLog.ExRate, dbo.tblPayroll_VesselLog.VesselCode, dbo.tblAdmin_Vessels.Vessel, dbo.tblPayroll_Allottees.AllotteeID, dbo.tblAdmin_Banks.BankAbbrv, dbo.tblAdmin_Branches.BranchName, dbo.tblAdmin_Positions.IDPosDep, dbo.tblPayroll_VesselLog.PrincipalCode, dbo.tblPayroll_VesselLog.Payroll_Period, dbo.tblAdmin_Branches.BankCode, dbo.tblAdmin_Positions.Officer, dbo.tblPayroll_Details.BatchNum, dbo.tblAdmin_Vessels.BatchNo, dbo.tblPayroll_VesselLog.PayrollID, dbo.tblPayroll_Details.SeamanID, dbo.tblAdmin_Positions.PositionAbbrvFROM dbo.tblAdmin_Vessels RIGHT OUTER JOIN dbo.tblAdmin_Banks RIGHT OUTER JOIN dbo.tblAdmin_Branches ON dbo.tblAdmin_Banks.BankCode = dbo.tblAdmin_Branches.BankCode RIGHT OUTER JOIN dbo.tblPayroll_Allottees RIGHT OUTER JOIN dbo.tblPayroll_Details RIGHT OUTER JOIN dbo.tblPayroll_VesselLog ON dbo.tblPayroll_Details.PayrollID = dbo.tblPayroll_VesselLog.PayrollID AND dbo.tblPayroll_Details.PayrollPeriod = dbo.tblPayroll_VesselLog.Payroll_Period ON dbo.tblPayroll_Allottees.PayrollID = dbo.tblPayroll_Details.PayrollID AND dbo.tblPayroll_Allottees.SeamanID = dbo.tblPayroll_Details.SeamanID LEFT OUTER JOIN dbo.tblAdmin_Positions RIGHT OUTER JOIN dbo.tbl_SeamanMain ON dbo.tblAdmin_Positions.PositionCode = dbo.tbl_SeamanMain.PositionCode ON dbo.tblPayroll_Details.SeamanID = dbo.tbl_SeamanMain.SeamanID ON dbo.tblAdmin_Branches.BranchCode = dbo.tblPayroll_Allottees.BranchCode ON dbo.tblAdmin_Vessels.VesselCode = dbo.tblPayroll_VesselLog.VesselCodeWHERE (dbo.tblPayroll_Details.Included = 1) AND (dbo.tblPayroll_Allottees.PaymentType = 1) AND (dbo.tbl_SeamanMain.IsSeamanActive = 1) AND (dbo.tblPayroll_VesselLog.Closed = 1) AND (dbo.tblPayroll_Allottees.NetAllotment > 0) AND (dbo.tblAdmin_Branches.BankCode = 2) AND (dbo.tblAdmin_Vessels.Active = 1) AND (REPLACE(dbo.tblPayroll_Allottees.AccountNo, '-', '') IS NOT NULL) AND (dbo.tblPayroll_VesselLog.PrincipalCode = 170) AND (dbo.tblPayroll_VesselLog.Payroll_Period = 1004) |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-26 : 23:30:52
|
| what does estimated execution plan suggests? what are costly steps?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
chriztoph
Posting Yak Master
184 Posts |
Posted - 2010-04-26 : 23:43:02
|
| dbo.tblPayroll_Details.Included = Non-Clustereddbo.tblPayroll_Allottees.PaymentType = Non-Clustereddbo.tbl_SeamanMain.IsSeamanActive = Non-Clustereddbo.tblPayroll_VesselLog.Closed = Non-Clustereddbo.tblPayroll_Allottees.NetAllotment = Non-Clustereddbo.tblAdmin_Branches.BankCode = Non-Clustereddbo.tblAdmin_Vessels.Activedbo.tblPayroll_Allottees.AccountNo = Non-Clustereddbo.tblPayroll_VesselLog.PrincipalCode = Clustereddbo.tblPayroll_VesselLog.Payroll_Period = Non-ClusteredAm I correct with the indexing? can you give any suggestions on how to indexed properly..thanks..@visakh16, what do you mean estimated execution plan? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2010-04-26 : 23:45:28
|
| You are missing many indexes. Each join condition should be indexed. SQL Server automatically adds an index on primary keys, but it does not do it for us with foreign keys. Indexes should be added to most, if not all, foreign keys as those are what are typically used in joins.Some of the indexes you posted look to be unnecessary such as the one on Payroll_VesselLog.Closed. Are the only possible values 0 and 1? If that's the case, then the index needs to be dropped due to selectivity.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
chriztoph
Posting Yak Master
184 Posts |
Posted - 2010-04-26 : 23:51:37
|
| ok, thanks..so i need to indexed all those in joins(Foreign Keys).what's the maximum number of columns in one Index? |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-04-27 : 00:00:23
|
quote: Originally posted by chriztoph dbo.tblPayroll_Details.Included = Non-Clustereddbo.tblPayroll_Allottees.PaymentType = Non-Clustereddbo.tbl_SeamanMain.IsSeamanActive = Non-Clustereddbo.tblPayroll_VesselLog.Closed = Non-Clustereddbo.tblPayroll_Allottees.NetAllotment = Non-Clustereddbo.tblAdmin_Branches.BankCode = Non-Clustereddbo.tblAdmin_Vessels.Activedbo.tblPayroll_Allottees.AccountNo = Non-Clustereddbo.tblPayroll_VesselLog.PrincipalCode = Clustereddbo.tblPayroll_VesselLog.Payroll_Period = Non-ClusteredAm I correct with the indexing? can you give any suggestions on how to indexed properly..thanks..@visakh16, what do you mean estimated execution plan?
there's an option to view estimated execution plan from top menu------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
chriztoph
Posting Yak Master
184 Posts |
Posted - 2010-04-27 : 00:33:23
|
| thanks guys..it really works fine now..so fast.. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2010-04-27 : 00:38:13
|
quote: Originally posted by chriztoph ok, thanks..so i need to indexed all those in joins(Foreign Keys).what's the maximum number of columns in one Index?
Well you don't put them in one index. An index can only span one table, unless you are using indexed views which is unlikely. Don't worry about the maximum number of columns in an index (the value is in BOL but I don't have it with me at the moment), you'll never reach the maximum.Tara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
 |
|
|
chriztoph
Posting Yak Master
184 Posts |
Posted - 2010-05-03 : 23:10:40
|
| how to reindex all the indexes of all my databases? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
chriztoph
Posting Yak Master
184 Posts |
Posted - 2010-05-05 : 03:27:39
|
| Last question for this post..what is the best type of index for Foreign Keys?Clustered or Non-Clustered? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
chriztoph
Posting Yak Master
184 Posts |
Posted - 2010-05-05 : 03:48:49
|
| Ok thanks.. |
 |
|
|
|