so suppose I have this query:
SELECT * FROM table1 A, table1 B where A.id = B.id;
even if there is an index on id on table1, it would still scan the entire table…is there a way to speed this up so that it doesn’t scan the entire table?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Though I do not have your execution plan in front of my, this is actually only scanning
TableAmost likely, and the reason for that is because you have no other conditions onTableA. It should be seeking onTableBat this time just because it’s statistical. Now, if you were to provide another condition forTableA, and that condition met an index, you would find that it was not scanning the entire table.To further that, if the index on
TableAwas a covered index for the query it would actually never even read a data page forTableA.And to further that, if there were a foreign key constraint between
TableAandTableBand you weren’t reading anything more fromTableBthan the id field it would also never read a data page.And to further that, even if you did need data from
TableB, if that data were on an index it still wouldn’t have to read a data page.But finally, because you’re selecting
*, it’s unlikely this will ever be a very efficient query because it’s selecting all columns from both tables.I hope that wasn’t too long winded but I wanted to make sure that you knew where I was coming from.