Click here to Skip to main content
15,899,825 members
Home / Discussions / Database
   

Database

 
QuestionSplit table Pin
sujithkumarsl24-Jun-09 20:46
sujithkumarsl24-Jun-09 20:46 
AnswerRe: Split table Pin
WoutL24-Jun-09 21:55
WoutL24-Jun-09 21:55 
GeneralRe: Split table Pin
sujithkumarsl24-Jun-09 22:01
sujithkumarsl24-Jun-09 22:01 
GeneralRe: Split table Pin
J4amieC25-Jun-09 0:26
J4amieC25-Jun-09 0:26 
GeneralRe: Split table Pin
sujithkumarsl25-Jun-09 0:30
sujithkumarsl25-Jun-09 0:30 
GeneralRe: Split table Pin
Mycroft Holmes25-Jun-09 0:54
professionalMycroft Holmes25-Jun-09 0:54 
GeneralRe: Split table Pin
sujithkumarsl25-Jun-09 1:15
sujithkumarsl25-Jun-09 1:15 
QuestionSQL Profiler for Oracle? Pin
devvvy24-Jun-09 20:43
devvvy24-Jun-09 20:43 
AnswerRe: SQL Profiler for Oracle? Pin
r a m e s h25-Jun-09 0:25
r a m e s h25-Jun-09 0:25 
AnswerQuest tools Pin
David Mujica25-Jun-09 2:52
David Mujica25-Jun-09 2:52 
GeneralRe: Quest tools Pin
devvvy25-Jun-09 4:15
devvvy25-Jun-09 4:15 
GeneralQuery for finding high read SQL statements Pin
David Mujica25-Jun-09 4:34
David Mujica25-Jun-09 4:34 
GeneralRe: Query for finding high read SQL statements Pin
devvvy25-Jun-09 4:35
devvvy25-Jun-09 4:35 
Questionhow to check duplicate Id record in table: Pin
LTMKH24-Jun-09 19:15
LTMKH24-Jun-09 19:15 
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 

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.