Solved

Which table first?

Posted on 1998-03-18
1
383 Views
Last Modified: 2010-05-18
I have two tables; the first table has 2 million records, where 1 column is called DEA_NO, which 1 million records has DEA_NO = NULL.  The table has a non-clustered index on this column.  The second table has about 140 records, and a column called DEA_NO (same type and size as in table one).  Using the following query:

Update Table_Two
Set A.ME_Number = Table_One.ME_Number
From Table_Two A, Table_One(3)
Where A.DEA_NO = Table_One.DEA_NO

with ShowPlan ON, Sybase shows that it wants to use Table_One first (with the forced index) matching Table_Two with a table scan.  Unfortunately, this actually works like a table scan on Table_One anyway, only we are traversing the table in DEA_NO order.  Why does Sybase insist on using Table_One first, instead of moving through the 140 records in Table_Two, looking up the records (which are indexed) in Table_One.  

Thanks.

Brent
0
Comment
Question by:bknouse
1 Comment
 
LVL 2

Accepted Solution

by:
jbiswas earned 50 total points
ID: 1098378
Looks like you are working with Doctor profiles for a pharmaceutical application. Firstly it would help to know what sybase software you are using. If you are SQL Anywhere, you basically can't do much, except maybe try and reindex both the ME# and DEA# fields in the two tables.

If you are using Sybase then what version of sybase are you using. Syatem 10 was notorious for doing what you are observing , but I haven't seen anything like this with system 11. Either way, you can drop and recreate the index (on both ME# and DEA#) and see if anything is different. If that doesn't work, try using the "forceindex" clause. I haven't used it in a while, so please look up forceindex in the sybooks documentation. It tells you how to force the query optimizer to use your index.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
A procedure for exporting installed hotfix details of remote computers using powershell
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now