May 14, 2012

sp_MSenumpartialdeletes (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_MSenumpartialdeletes(int @maxrows
, int @tablenick
, uniqueidentifier @rowguid
, nvarchar @tablenotbelongs
, int @bookmark
, int @specified_article_only
, int @compatlevel
, uniqueidentifier @pubid
, bit @enumentirerowmetadata)

MetaData:

 --  If the default parameters change, make sure to adjust the corresponding values in OSQL_Q_ENUMPARTIALDELETES_90.  
create procedure sys.sp_MSenumpartialdeletes
(@maxrows int,
@tablenick int,
@rowguid uniqueidentifier,
@tablenotbelongs nvarchar(255),
@bookmark int = NULL,
@specified_article_only int = 0,
@compatlevel int = 10, -- backward compatibility level, default=Sphinx
@pubid uniqueidentifier = NULL,
@enumentirerowmetadata bit= 1)
as
declare @tnstring nvarchar(12)
declare @lowrangestr nvarchar(12)
declare @highrangestr nvarchar(12)
declare @pubidstr varchar(40)
declare @last_art_processing_order int
declare @last_art_processing_order_str varchar(12)
declare @rowguid_clause nvarchar(100)

--
-- do permission checking
--
declare @retcode int
exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @tablenick
if @retcode<>0 or @@ERROR<>0 return (1)

declare @selecttop nvarchar(50)
if (@maxrows = 0)
set @selecttop= 'select'
else
set @selecttop= 'select top ' + cast(@maxrows as nvarchar(9))

declare @metadatacol nvarchar(200)
declare @metadatacol2 nvarchar(200)

if 0 = @enumentirerowmetadata
begin
if 1 > @tablenick or 0 = @specified_article_only
begin
set @metadatacol= 'sys.fn_MSgeneration_downloadonly(generation, tablenick), sys.fn_MSvector_downloadonly(lineage, tablenick)'
set @metadatacol2= 'sys.fn_MSgeneration_downloadonly(t.generation, tablenick), sys.fn_MSvector_downloadonly(lineage, tablenick)'
end
else
begin
set @metadatacol= 'null, null'
set @metadatacol2= 'null, null'
end
end
else if @compatlevel >= 90
begin
set @metadatacol= 'coalesce(generation, 0), lineage'
set @metadatacol2= 'coalesce(t.generation, 0), lineage'
end
else
begin
set @metadatacol= 'coalesce(generation, 0), {fn LINEAGE_90_TO_80(lineage)}'
set @metadatacol2= 'coalesce(t.generation, 0), {fn LINEAGE_90_TO_80(lineage)}'
end

if @pubid is not null
begin
select @pubidstr = '''' + convert(varchar(36), @pubid) + ''''
if @tablenick > 0
begin
exec sys.sp_MSget_article_processing_order @tablenick, @pubid, @last_art_processing_order output
select @last_art_processing_order_str = convert(varchar(12), @last_art_processing_order)
end
end


if (@tablenick < 1)
begin
if @pubid is null
execute (@selecttop + ' tablenick, rowguid, ' + @metadatacol + ', type, bookmark from ' + @tablenotbelongs + '
order by tablenick desc, rowguid asc'
)
else
execute (@selecttop + ' t.tablenick, t.rowguid, ' + @metadatacol2 + ', t.type, t.bookmark
from '
+ @tablenotbelongs + ' t, dbo.sysmergearticles sma
where t.tablenick = sma.nickname
and sma.pubid = '
+ @pubidstr + '
order by sma.processing_order desc, t.tablenick desc, t.rowguid asc'
)
IF @@ERROR <>0
begin
return (1)
end

end
else
begin
set @tnstring = convert(nchar, @tablenick)
if @rowguid is NULL or @rowguid = '00000000-0000-0000-0000-000000000000'
select @rowguid_clause = ' '
else
select @rowguid_clause = ' and rowguid > ''' + convert(nchar(36), @rowguid) + ''' '

--
-- If a 7.0 SP1 Merge agent is calling this sp, it passed a valid bookmark parameter
-- Use the bookmark column in the ##belongs_<> table to retrieve the next batch of rows
--
if @bookmark is NOT NULL
begin
set @lowrangestr = convert(nchar, @bookmark)
set @highrangestr = convert(nchar, (@bookmark + @maxrows))

if (@specified_article_only = 1)
begin
-- don't rely on @highrangestr since it will be equal to @lowrangestr if @maxrows=0.
execute (@selecttop + ' tablenick, rowguid, ' + @metadatacol + ', type, bookmark from ' + @tablenotbelongs + '
where tablenick = '
+ @tnstring + ' and
bookmark > '
+ @lowrangestr + '
order by tablenick, rowguid'
)

if @@ERROR<>0
begin
return (1)
end


end
else
begin
if @pubid is null
execute ('select tablenick, rowguid, ' + @metadatacol + ', type, bookmark from ' + @tablenotbelongs + '
where ((tablenick = '
+ @tnstring + ' and
bookmark > '
+ @lowrangestr + ' and bookmark <= ' + @highrangestr + ') or
tablenick < '
+ @tnstring + ')
order by tablenick desc, rowguid asc'
)
else
execute ('select t.tablenick, t.rowguid, ' + @metadatacol2 + ', t.type, t.bookmark
from '
+ @tablenotbelongs + ' t, dbo.sysmergearticles sma
where t.tablenick = sma.nickname
and sma.pubid = '
+ @pubidstr + '
and
(
(t.tablenick = '
+ @tnstring + ' and t.bookmark > ' + @lowrangestr + ' and t.bookmark <= ' + @highrangestr + ') or
(sma.processing_order = '
+ @last_art_processing_order_str + ' and t.tablenick < ' + @tnstring + ') or
sma.processing_order < '
+ @last_art_processing_order_str + '
)
order by sma.processing_order desc, t.tablenick desc, t.rowguid asc'
)

if @@ERROR<>0
begin
return (1)
end

end
end

--
-- Backward compatibilty mode : If a 7.0 Merge agent is calling this sp, it will pass a NULL bookmark parameter
-- Use the rowguid and set rowcount to retrieve the next batch of rows
--
else
begin
if (@specified_article_only = 1)
begin
execute (@selecttop + ' tablenick, rowguid, ' + @metadatacol + ', type from ' + @tablenotbelongs + '
where tablenick = '
+ @tnstring + @rowguid_clause + '
order by tablenick, rowguid'
)
IF @@ERROR <>0
begin
return (1)
end

end
else
begin
if @pubid is null
execute (@selecttop + ' tablenick, rowguid, ' + @metadatacol + ', type from ' + @tablenotbelongs + '
where ((tablenick = '
+ @tnstring + @rowguid_clause + ') or tablenick < ' + @tnstring + ')
order by tablenick desc, rowguid asc'
)
else
execute (@selecttop + ' t.tablenick, t.rowguid, ' + @metadatacol2 + ', t.type
from '
+ @tablenotbelongs + ' t, dbo.sysmergearticles sma
where t.tablenick = sma.nickname
and sma.pubid = '
+ @pubidstr + '
and
(
(tablenick = '
+ @tnstring + @rowguid_clause + ') or
(sma.processing_order = '
+ @last_art_processing_order_str + ' and t.tablenick < ' + @tnstring + ') or
sma.processing_order < '
+ @last_art_processing_order_str + '
)

order by sma.processing_order desc, t.tablenick desc, t.rowguid asc'
)

IF @@ERROR <>0
begin
return (1)
end

end
end
end
return (0)

No comments:

Post a Comment

Total Pageviews