Click here to Skip to main content
15,914,905 members
Home / Discussions / Database
   

Database

 
GeneralRe: Query Optimization - MCAD question. Pin
Jeff Varszegi18-Dec-03 14:49
professionalJeff Varszegi18-Dec-03 14:49 
GeneralRe: Query Optimization - MCAD question. Pin
CillyMe18-Dec-03 16:00
CillyMe18-Dec-03 16:00 
GeneralRe: Query Optimization - MCAD question. Pin
Jeff Varszegi18-Dec-03 17:00
professionalJeff Varszegi18-Dec-03 17:00 
GeneralRe: Query Optimization - MCAD question. Pin
CillyMe18-Dec-03 22:04
CillyMe18-Dec-03 22:04 
GeneralRe: Query Optimization - MCAD question. Pin
Jeff Varszegi19-Dec-03 6:12
professionalJeff Varszegi19-Dec-03 6:12 
GeneralRe: Query Optimization - MCAD question. Pin
Jeff Varszegi19-Dec-03 6:17
professionalJeff Varszegi19-Dec-03 6:17 
GeneralRe: Query Optimization - MCAD question. Pin
CillyMe19-Dec-03 15:42
CillyMe19-Dec-03 15:42 
GeneralRe: Query Optimization - MCAD question. Pin
Mike Dimmick5-Jan-04 6:20
Mike Dimmick5-Jan-04 6:20 
Going through the options:

a) has no effect, since that's purely syntactic convenience: SQL Server translates that to PolicyDate >= '2/1/2001' AND PolicyDate <= '3/4/2002' anyway.

b) A hash might work better, but it's clear that the index isn't being used, as you say. A hash join constructs a hash table of one side of the join, which the other looks up in, whereas a loop join simply loops over each side of the result set looking for matches.

c) According to http://www.sql-server-performance.com/hints_table.asp[^], WITH(INDEX(0)) forces a table scan - precisely what we're trying to avoid. That same page recommends using index names rather than index IDs, because the IDs can change if the indexes are dropped and recreated - in other words, they're fragile.

d) Updates any index statistics that are out of date. SQL Server uses the statistics to determine how good an index might be for finding the requested information.

e) Rebuilding the index will incidentally update the statistics, but it's a lot of work that might not be necessary (and locks everyone out of the table while it does it).

Assuming that appropriate indexes already exist (and I don't know which table contains which fields), then updating statistics might work. If there are no appropriate indexes, it won't help - at least one of the tables will have to be scanned to find the rows matching the WHERE clause, then those rows joined onto the other table. The problem description doesn't say whether the index scan was caused by the join operation or by the original lookup.

Answering your question 3, I looked up 'hash join' in my copy of Inside SQL Server 2000 (which I thoroughly recommend). If there isn't a good index for the join (in this case, no index on AgentPolicy.PolicyNumber), a hash join might be cheaper. However, it can only be done for an equijoin (i.e. the join condition uses '=') and can take a lot of memory. The query optimiser won't use it if it thinks it will need to do more I/O to store and retrieve the temporary hash table than it will to repeatedly retrieve the original data.

This is one reason to keep hints out of your queries - they tend to be very system specific. What helps one system might hurt another.
GeneralSqlException in ADO.NET Pin
Y. Liu18-Dec-03 4:02
Y. Liu18-Dec-03 4:02 
GeneralRe: SqlException in ADO.NET Pin
Jeff Varszegi18-Dec-03 14:50
professionalJeff Varszegi18-Dec-03 14:50 
GeneralRe: SqlException in ADO.NET Pin
Y. Liu19-Dec-03 4:36
Y. Liu19-Dec-03 4:36 
GeneralRe: SqlException in ADO.NET Pin
Jeff Varszegi19-Dec-03 5:43
professionalJeff Varszegi19-Dec-03 5:43 
GeneralRe: SqlException in ADO.NET Pin
SimonS24-Dec-03 8:31
SimonS24-Dec-03 8:31 
GeneralDataSet Pin
Large Data File17-Dec-03 20:40
Large Data File17-Dec-03 20:40 
GeneralRe: DataSet Pin
Not Active18-Dec-03 2:53
mentorNot Active18-Dec-03 2:53 
GeneralSql question Pin
pankajdaga17-Dec-03 7:18
pankajdaga17-Dec-03 7:18 
GeneralRe: Sql question Pin
Not Active17-Dec-03 8:22
mentorNot Active17-Dec-03 8:22 
GeneralRe: Sql question Pin
pankajdaga17-Dec-03 9:24
pankajdaga17-Dec-03 9:24 
GeneralRe: Sql question Pin
jeff_martin17-Dec-03 10:23
jeff_martin17-Dec-03 10:23 
GeneralRe: Sql question Pin
pankajdaga17-Dec-03 11:23
pankajdaga17-Dec-03 11:23 
GeneralPlease help me with Datagrid Pin
roger.nie17-Dec-03 6:24
roger.nie17-Dec-03 6:24 
Generalhoe to get ADO info Pin
xprtguro16-Dec-03 21:15
xprtguro16-Dec-03 21:15 
QuestionHow to use ado.net to open mdb file in vb.net Pin
m_3ryan16-Dec-03 5:29
m_3ryan16-Dec-03 5:29 
AnswerRe: How to use ado.net to open mdb file in vb.net Pin
Colin Angus Mackay16-Dec-03 5:53
Colin Angus Mackay16-Dec-03 5:53 
AnswerRe: How to use ado.net to open mdb file in vb.net Pin
Mike Ellison17-Dec-03 13:40
Mike Ellison17-Dec-03 13:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.