July 8, 2008 at 9:11 am
Hi all,
I just come across the .Write clause.
Was wondering about some execution plan differences with the following statements
Query1
UPDATE @tbl
SET col = stuff(col,1,0,'what happens here')
WHERE Id = 2
Query2
UPDATE @tbl --ASSERT
SET col .WRITE('what happens here',0,0)
WHERE Id = 1
The plans are almost exactly the same except that Query1 one has an "compute Scalar" in the plan and Query2 has "Assert".
My question is what does those mean?
Also what is the benifit of using the .WRITE over the Stuff ?
Thanks
Chris
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
July 8, 2008 at 9:27 am
From BOL ...
.WRITE ( expression, @Offset , @Length )
Specifies that a section of the value of column_name is to be modified. expression replaces @Length units starting from @Offset of column_name. Only columns of varchar(max), nvarchar(max), or varbinary(max) can be specified with this clause. column_name cannot be NULL and cannot be qualified with a table name or table alias.
expression is the value that is copied to column_name. expression must evaluate to or be able to be implicitly cast to the column_name type. If expression is set to NULL, @Length is ignored, and the value in column_name is truncated at the specified @Offset.
@Offset is the starting point in the value of column_name at which expression is written. @Offset is a zero-based ordinal position, is bigint, and cannot be a negative number. If @Offset is NULL, the update operation appends expression at the end of the existing column_name value and @Length is ignored. If @Offset is greater than the length of the column_name value, the Microsoft SQL Server 2005 Database Engine returns an error. If @Offset plus @Length exceeds the end of the underlying value in the column, the deletion occurs up to the last character of the value. If @Offset plus LEN(expression) is greater than the underlying declared size, an error is raised.
@Length is the length of the section in the column, starting from @Offset, that is replaced by expression. @Length is bigint and cannot be a negative number. If @Length is NULL, the update operation removes all data from @Offset to the end of the column_name value.
The UPDATE statement is logged; however, partial updates to large value data types using the .WRITE clause are minimally logged.
So to me the benefit is mainly the minimal logging of the update.
______________________________________________________________________
Personal Motto: Why push the envelope when you can just open it?
If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.
Jason L. SelburgJuly 8, 2008 at 9:35 am
Thanks Jason,
The login I would think would make a difference yes good point.
does anyone have any feedback on the main difference/benifits of "assert" vs "compute scalar" in an execution plan?
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
July 8, 2008 at 2:56 pm
.write() is an in-place edit (ergo the minimal logging) and will perform faster. if you've got a 10mb column value and only want to change/add 400 bytes of data, it's much less resource intensive to specify where the 400 bytes go rather than rewrite the full 10mb.
July 9, 2008 at 2:43 am
Thanks very much for tht explination 🙂
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply