Showing posts with label explain. Show all posts
Showing posts with label explain. Show all posts

Wednesday, March 28, 2012

ROWGUIDCOL column

hi
Can any one explain impact of tunning or query optimization that uses
ROWGUIDCOL?
Thanks
Kalyan
Kalyan wrote:
> hi
> Can any one explain impact of tunning or query optimization that uses
> ROWGUIDCOL?
>
> Thanks
> Kalyan
Can you explain in more detail what you are looking for. Using a GUID as
opposed to a INT IDENTITY, for example, doesn't really hurt performance,
except for the fact that a GUID takes up more space than an INT (16 vs 4
bytes). In that respect, the INT is a better choice.
David Gugick
Imceda Software
www.imceda.com

ROWGUIDCOL column

hi
Can any one explain impact of tunning or query optimization that uses
ROWGUIDCOL?
Thanks
KalyanKalyan wrote:
> hi
> Can any one explain impact of tunning or query optimization that uses
> ROWGUIDCOL?
>
> Thanks
> Kalyan
Can you explain in more detail what you are looking for. Using a GUID as
opposed to a INT IDENTITY, for example, doesn't really hurt performance,
except for the fact that a GUID takes up more space than an INT (16 vs 4
bytes). In that respect, the INT is a better choice.
David Gugick
Imceda Software
www.imceda.com

ROWGUIDCOL column

hi
Can any one explain impact of tunning or query optimization that uses
ROWGUIDCOL?
Thanks
KalyanKalyan wrote:
> hi
> Can any one explain impact of tunning or query optimization that uses
> ROWGUIDCOL?
>
> Thanks
> Kalyan
Can you explain in more detail what you are looking for. Using a GUID as
opposed to a INT IDENTITY, for example, doesn't really hurt performance,
except for the fact that a GUID takes up more space than an INT (16 vs 4
bytes). In that respect, the INT is a better choice.
--
David Gugick
Imceda Software
www.imceda.com

Monday, March 26, 2012

Row_number selecting from a complex select statement

Hi,

Code Snippet


This is difficult to explain in words, but the following code outlines what I am trying to do:

with myTableWithRowNum as
(
select 'row' = row_number() over (order by insertdate desc), myValue
from
(
select table1Id As myValue from myTable1
union
select table2Id As myValue from myTable2
)
)

select * from myTableWithRowNum


Can anyone think of a work around so that I can use the Row_Number function where the data is coming from a union?

The following query might help you,

Code Snippet

;with UnionResult(myvalue,insertdate)

as

(

select table1Id As myValue,insertdate from myTable1

union

select table2Id As myValue,insertdate from myTable2

),

OrderedResult(myValue,Row)

as

(

select myValue, row_number() over (order by insertdate desc)

from UnionResult

)

select * from OrderedResult

|||

I m not sure I understand your requirment correctly,anyhow your query throws error,

Try the following

Code Snippet

;with myTableWithRowNum as

(

select 'row' = row_number() over (order by insertdate desc), myValue

from

(

select insertdate,table1Id As myValue from myTable1

union

select insertdate,table2Id As myValue from myTable2

) as temp

)

select * from myTableWithRowNum

|||Thanks that's exactly what I'm looking for.
sql

ROW_NUMBER and LEFT JOIN

Hi,

I don't have a problem, but I have run into an SQL 2005 "behavior" that I can't explain. So, I thought I'd ask here.

My question is how come that the below script will return 1 row if DISTINCT keyword is present and 3 rows if it's not? I would have guessed that it should return 3 rows for both versions of the batch.

Declare @.Movies TABLE(ID int,Namenvarchar(100))

Declare @.Comments TABLE(ID int, MovieID int, Comment nvarchar(100))

INSERTINTO @.Movies VALUES(1,'Pulp Fiction')

INSERTINTO @.Comments VALUES(1, 1,'Good movie.')

INSERTINTO @.Comments VALUES(2, 1,'Sucked!')

INSERTINTO @.Comments VALUES(3, 1,'Terrific.')

SELECT

DISTINCT

ROW_NUMBER()OVER(ORDERBY M.ID DESC)AS RowNum,

M.ID

FROM

@.Movies AS M

LEFTJOIN

@.Comments AS C

ON

C.MovieID = M.ID

GO

In the Execution Plan I can see that, if the keyword DISTINCT is present, SQL won't "touch" the Comments table, and if DISTINCT is present it will deal with the Comments table, so that gives me a clue, but I'd still like to hear an offical explanation if there is one.

Thanks.

Since you haven't included any columns from the @.Comments table, the "distinct" will cause the same number of rows to be returned with or without the left join to that table, so the query does not require access to @.Comments.

Ron Rice