Click here to Skip to main content
15,889,992 members
Home / Discussions / Database
   

Database

 
AnswerRe: how to check duplicate Id record in table: Pin
Mycroft Holmes24-Jun-09 19:28
professionalMycroft Holmes24-Jun-09 19:28 
GeneralRe: how to check duplicate Id record in table: Pin
WoutL24-Jun-09 20:19
WoutL24-Jun-09 20:19 
GeneralRe: how to check duplicate Id record in table: Pin
Mycroft Holmes24-Jun-09 20:37
professionalMycroft Holmes24-Jun-09 20:37 
GeneralRe: how to check duplicate Id record in table: Pin
LTMKH30-Jun-09 15:08
LTMKH30-Jun-09 15:08 
GeneralRe: how to check duplicate Id record in table: Pin
Mycroft Holmes30-Jun-09 17:47
professionalMycroft Holmes30-Jun-09 17:47 
GeneralRe: how to check duplicate Id record in table: Pin
LTMKH30-Jun-09 18:00
LTMKH30-Jun-09 18:00 
AnswerRe: how to check duplicate Id record in table: Pin
Niladri_Biswas24-Jun-09 20:19
Niladri_Biswas24-Jun-09 20:19 
QuestionSame Execution Plans / Different Actual Number of Rows [modified] Pin
Meysam Mahfouzi24-Jun-09 4:27
Meysam Mahfouzi24-Jun-09 4:27 
I have got two queries both of which generate the same execution plan:

query 1:
SELECT TOP 10 *
FROM news
CROSS APPLY (SELECT TOP 1 NetworkID FROM ItemNetwork WHERE ItemID = news.ID) itemNet


query 2:
SELECT TOP 10 *
FROM news
CROSS APPLY (SELECT TOP 1 NetworkID FROM ItemNetwork WHERE ItemID = news.ID AND ItemType = 0) itemNet

ItemNetwork table has 4 columns:
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[ItemID] [bigint] NOT NULL,
[ItemType] [tinyint] NOT NULL,
[NetworkID] [int] NOT NULL



I have also created a non-clustered index on ItemNetwork table:
CREATE NONCLUSTERED INDEX [IX_ItemNetwork_ItemID_ItemType__NetworkID] ON ItemNetwork
(
	[ItemID] ASC,
	[ItemType] ASC
)
INCLUDE ( [NetworkID])


The first query takes one second to execute, while it takes 2 minutes for the second one to execute. The execution plan for both queries is the same. You can see the execution plan for the first query here[^] and for the second query here[^].

The only difference that can be seen between the two execution plans is the amount of data that comes out of news table. For the second query, we see a very big arrow coming out of news table. That is because the actual number of rows coming out of this table is 1534672 rows while for the first query, this number is 877 rows. For both queries, the estimated number of rows is 10 (because of top 10 clause). Look at the actual number of rows for both queries here[^] and here[^].

The only difference between the two queries is this condition:
ItemType = 0


I also updated the statistics for all the tables involved, but it didn't make any difference.

Could somebody please tell me how I can make the second query execute as fast as the first one?

p.s. the total number of rows in News table is 1576612 rows, in Network table 1820 rows and in ItemNetwork table 42164 rows

modified on Thursday, June 25, 2009 3:19 AM

AnswerRe: Same Execution Plans / Different Actual Number of Rows Pin
DoctorMick24-Jun-09 5:54
DoctorMick24-Jun-09 5:54 
GeneralRe: Same Execution Plans / Different Actual Number of Rows Pin
Meysam Mahfouzi24-Jun-09 20:28
Meysam Mahfouzi24-Jun-09 20:28 
Questionconnection string and dynamic connection string Pin
Phumlani Kunene24-Jun-09 3:55
Phumlani Kunene24-Jun-09 3:55 
AnswerRe: connection string and dynamic connection string Pin
J4amieC24-Jun-09 5:50
J4amieC24-Jun-09 5:50 
AnswerRe: connection string and dynamic connection string Pin
Niladri_Biswas24-Jun-09 17:16
Niladri_Biswas24-Jun-09 17:16 
QuestionWhat is code for log_In in ASP Pin
Phumlani Kunene24-Jun-09 3:49
Phumlani Kunene24-Jun-09 3:49 
AnswerRe: What is code for log_In in ASP Pin
J4amieC24-Jun-09 5:51
J4amieC24-Jun-09 5:51 
AnswerRe: What is code for log_In in ASP Pin
Jerry Hammond24-Jun-09 6:27
Jerry Hammond24-Jun-09 6:27 
AnswerRe: What is code for log_In in ASP Pin
Niladri_Biswas24-Jun-09 18:52
Niladri_Biswas24-Jun-09 18:52 
QuestionProblem when creating query on base of combination Pin
Rupesh Kumar Swami24-Jun-09 0:00
Rupesh Kumar Swami24-Jun-09 0:00 
AnswerRe: Problem when creating query on base of combination Pin
Syed Mehroz Alam24-Jun-09 1:11
Syed Mehroz Alam24-Jun-09 1:11 
GeneralRe: Problem when creating query on base of combination Pin
Rupesh Kumar Swami24-Jun-09 1:45
Rupesh Kumar Swami24-Jun-09 1:45 
AnswerRe: Problem when creating query on base of combination [modified] Pin
Niladri_Biswas24-Jun-09 2:16
Niladri_Biswas24-Jun-09 2:16 
GeneralRe: Problem when creating query on base of combination Pin
J4amieC24-Jun-09 2:21
J4amieC24-Jun-09 2:21 
GeneralRe: Problem when creating query on base of combination Pin
Niladri_Biswas24-Jun-09 2:23
Niladri_Biswas24-Jun-09 2:23 
GeneralRe: Problem when creating query on base of combination Pin
Rupesh Kumar Swami3-Jul-09 6:08
Rupesh Kumar Swami3-Jul-09 6:08 
QuestionSQL proxy server Pin
Maddie from Dartford23-Jun-09 19:58
Maddie from Dartford23-Jun-09 19:58 

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.