Tuesday, March 27, 2012
Field Encryption
uilt-in function of SQL Server to encrypt these, or should I use my own algo
rythm?
TIA,
Will TThere is none built-in. You can search the archives of this newsgroup for
some ideas. Also check:
www.sqlsecurity.com
Anith|||See:
http://www.microsoft.com/technet/pr...n/sp3sec03.mspx
Storing Credentials
Avoid storing credentials in any form. The best practice is to use only
Windows Authentication and never handle credentials at all. If your
application must connect with a system outside a trusted domain, however,
credential management may become necessary. In this case, the best practice
is to encrypt the credentials using the DPAPI and save them in a registry
key that uses an ACL.
Thanks,
Kevin McDonnell
Microsoft Corporation
This posting is provided AS IS with no warranties, and confers no rights.|||If you are storing user passwords for your application and need a small leve
l of encryption to use. Try the undocumented
PWDENCRYPT:
String function used to encrypt a string using SQL Server's password encrypt
ion algorithm.
SELECT PWDENCRYPT('string')
and
PWDCOMPARE
String function used to compare an unencrypted string to the value returned
by the PWDENCRYPT function.
SELECT CASE ISNULL(PWDCOMPARE ('sa',(SELECT password FROM master.dbo.syslogi
ns WHERE name = 'sa')),0)
WHEN 0 THEN 'Not the same'
WHEN 1 THEN 'Password the same as the login'
END
No real decrypt function available.
These two encryption functions are what SQL Server uses to stored its own pa
sswords, are not extremely strong. Commerical products are available that ar
e much stronger.
Randy
www.Database-Security.Info|||To add to Randy's response, one shouldn't use undocumented features in
production code. These may be changed in future SQL Server versions or
service packs and break your application.
Hope this helps.
Dan Guzman
SQL Server MVP
"Will T" <anonymous@.discussions.microsoft.com> wrote in message
news:158D0D8C-1B5B-4633-AA05-0FAAC0352826@.microsoft.com...
> I want to save passwords in an encrypted format in my database. Is there a
built-in function of SQL Server to encrypt these, or should I use my own
algorythm?
> TIA,
> Will T|||pls send reply sooooooooooooon
****************************************
******************************
Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET
resources...sql
field Compatable with uniqueidentifier (GUID)
I am looking for some field, which is compatable with GUID or maybe
some function which converts a CHAR/VARCHAR/INT to uniqueidentifier
(GUID) ?
Any suggestions?
Hi
You cannot convert directly a value as CHAR(n)/VARCHAR(n) as
DECLARE @.str VARCHAR(1)
SET @.str = 'V'
SELECT CAST(@.str as UNIQUEIDENTIFIER)
What do you try to accomplish?
"hack_tick" <sharma.vasudev@.gmail.com> wrote in message
news:1131530112.619103.39140@.z14g2000cwz.googlegro ups.com...
> hi there Guys!
> I am looking for some field, which is compatable with GUID or maybe
> some function which converts a CHAR/VARCHAR/INT to uniqueidentifier
> (GUID) ?
> Any suggestions?
>
|||Thankyou for the Reply, currently I want to add some dozens of Test
data, which are reference across using GUID as the foreign Key, in
order for me to have the foreign key in other table I was looking for
someway to have my own simple GUID so that i can remember what i did :-)
sql
field Compatable with uniqueidentifier (GUID)
I am looking for some field, which is compatable with GUID or maybe
some function which converts a CHAR/VARCHAR/INT to uniqueidentifier
(GUID) ?
Any suggestions?Hi
You cannot convert directly a value as CHAR(n)/VARCHAR(n) as
DECLARE @.str VARCHAR(1)
SET @.str = 'V'
SELECT CAST(@.str as UNIQUEIDENTIFIER)
What do you try to accomplish?
"hack_tick" <sharma.vasudev@.gmail.com> wrote in message
news:1131530112.619103.39140@.z14g2000cwz.googlegroups.com...
> hi there Guys!
> I am looking for some field, which is compatable with GUID or maybe
> some function which converts a CHAR/VARCHAR/INT to uniqueidentifier
> (GUID) ?
> Any suggestions?
>|||Thankyou for the Reply, currently I want to add some dozens of Test
data, which are reference across using GUID as the foreign Key, in
order for me to have the foreign key in other table I was looking for
someway to have my own simple GUID so that i can remember what i did :-)
field Compatable with uniqueidentifier (GUID)
I am looking for some field, which is compatable with GUID or maybe
some function which converts a CHAR/VARCHAR/INT to uniqueidentifier
(GUID) ?
Any suggestions?Hi
You cannot convert directly a value as CHAR(n)/VARCHAR(n) as
DECLARE @.str VARCHAR(1)
SET @.str = 'V'
SELECT CAST(@.str as UNIQUEIDENTIFIER)
What do you try to accomplish?
"hack_tick" <sharma.vasudev@.gmail.com> wrote in message
news:1131530112.619103.39140@.z14g2000cwz.googlegroups.com...
> hi there Guys!
> I am looking for some field, which is compatable with GUID or maybe
> some function which converts a CHAR/VARCHAR/INT to uniqueidentifier
> (GUID) ?
> Any suggestions?
>|||Thankyou for the Reply, currently I want to add some dozens of Test
data, which are reference across using GUID as the foreign Key, in
order for me to have the foreign key in other table I was looking for
someway to have my own simple GUID so that i can remember what i did :-)
Field Alias as Function
month +1 ie datename(month, getdate()) and datename(month,
dateadd(mm,1,getdate())), so instead of '1' and '2' I have January and
February
Select
case when p1.ExpectedDeliveryDate >= @.Start and p1.ExpectedDeliveryDate <=
dateadd(dd,-1,dateadd(mm,1,@.Start)) then convert(int,ROUND(Q1.TotalValue /
1000, 0)) end as '1',
case when p1.ExpectedDeliveryDate >= dateadd(dd,-1,dateadd(mm,1,@.Start)) and
p1.ExpectedDeliveryDate <= dateadd(dd,-1,dateadd(mm,2,@.Start)) then
convert(int,ROUND(Q1.TotalValue / 1000, 0)) end as '2',
Can anyone please advise how i can acheive this
Regards
JohnJohn wrote:
> I want to change the alias of the fields below to the current month and th
e
> month +1 ie datename(month, getdate()) and datename(month,
> dateadd(mm,1,getdate())), so instead of '1' and '2' I have January and
> February
> Select
> case when p1.ExpectedDeliveryDate >= @.Start and p1.ExpectedDeliveryDate <=
> dateadd(dd,-1,dateadd(mm,1,@.Start)) then convert(int,ROUND(Q1.TotalValue /
> 1000, 0)) end as '1',
> case when p1.ExpectedDeliveryDate >= dateadd(dd,-1,dateadd(mm,1,@.Start)) a
nd
> p1.ExpectedDeliveryDate <= dateadd(dd,-1,dateadd(mm,2,@.Start)) then
> convert(int,ROUND(Q1.TotalValue / 1000, 0)) end as '2',
> Can anyone please advise how i can acheive this
> Regards
> John
A query can't change aliases dynamically at runtime unless you
construct the query itself dynamically (dynamic SQL).
Why is the alias important to you? You don't have to use that column
name when you display or print the result so it ought to be easier to
retrieve a fixed column name and just display the month name in its
place in the client app or report. Most reporting tools for example
will allow you to add whatever dynamic column headings you require.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Thanks David, took you advise and formated column heading in report
John
"David Portas" <REMOVE_BEFORE_REPLYING_dportas@.acm.org> wrote in message
news:1138357083.736038.251280@.g44g2000cwa.googlegroups.com...
> John wrote:
> A query can't change aliases dynamically at runtime unless you
> construct the query itself dynamically (dynamic SQL).
> Why is the alias important to you? You don't have to use that column
> name when you display or print the result so it ought to be easier to
> retrieve a fixed column name and just display the month name in its
> place in the client app or report. Most reporting tools for example
> will allow you to add whatever dynamic column headings you require.
> --
> David Portas, SQL Server MVP
> Whenever possible please post enough code to reproduce your problem.
> Including CREATE TABLE and INSERT statements usually helps.
> State what version of SQL Server you are using and specify the content
> of any error messages.
> SQL Server Books Online:
> http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
> --
>
Friday, March 23, 2012
Features of a normal index comapred to a Full text index
My company is in the middle of coding a complex search function which
takes over most of the features that full text indexing contains (such
as stemming and stopping).
However from reading about full text indexing it appears that for a
column containing rows of pure text documents, the way that it indexes
the text is as follows: -
word id of row where word can be found
### #################################
car 0, 10, 256, 654
bike 20, 36, 92
skates 65,. 42
If this is the case I can see this improving search speeds for a large
database.
However we don't want any of the other features that full text
catalogue has as we do it ourselves.
My question is can we turn off all the extra features of full text
indexing (so we only left with a text index), or is a normal index
sufficient to provide the above example?
Many thanks for any help or advice
Kind Regards
Philip
With the Contains/ContainsTable keywords you get a strict match which it
sounds like what you are looking for. In otherwords stemming, and
wildcarding are disabled.
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
"Phi!" <philgoogle2003@.yahoo.com> wrote in message
news:42d3fa28.0408110112.15962c0@.posting.google.co m...
> Hello everyone,
> My company is in the middle of coding a complex search function which
> takes over most of the features that full text indexing contains (such
> as stemming and stopping).
> However from reading about full text indexing it appears that for a
> column containing rows of pure text documents, the way that it indexes
> the text is as follows: -
> word id of row where word can be found
> ### #################################
> car 0, 10, 256, 654
> bike 20, 36, 92
> skates 65,. 42
> If this is the case I can see this improving search speeds for a large
> database.
> However we don't want any of the other features that full text
> catalogue has as we do it ourselves.
> My question is can we turn off all the extra features of full text
> indexing (so we only left with a text index), or is a normal index
> sufficient to provide the above example?
> Many thanks for any help or advice
> Kind Regards
> Philip
|||Hello Hilary,
Thankyou for you help, just to make sure, when I enable full text
catalogs, does it index the text without stemming and stopping the
data.
By this i mean that is I had stored in the table "to be or not to be",
would the full text catalog contain indexes for to, be, or and not or
would it stem and stop the text.
Again thankyou for your help
Kind Regards
Phil
"Hilary Cotter" <hilaryk@.att.net> wrote in message news:<#XtB1t5fEHA.1972@.TK2MSFTNGP09.phx.gbl>...[vbcol=seagreen]
> With the Contains/ContainsTable keywords you get a strict match which it
> sounds like what you are looking for. In otherwords stemming, and
> wildcarding are disabled.
> --
> Hilary Cotter
> Looking for a book on SQL Server replication?
> http://www.nwsu.com/0974973602.html
>
> "Phi!" <philgoogle2003@.yahoo.com> wrote in message
> news:42d3fa28.0408110112.15962c0@.posting.google.co m...
|||The answer is complex. First off to,be, or, and not are all noise words and
as such they would not be indexed.
But to answer your question that depends on the word breaker. In general
the words would be indexed as they appear in the content. For some word
breakers different language rules dicate different indexing patterns, for
instance in the French word breaker, marie-claire is indexed as two
different words, marie and claire, however Marie-Claire is indexed as one
word (MarieClaire). The hyphen and the capitalization cause it to be indexed
as one word not two.
It is at query time when the search arguements might will be stemmed (when
you are doing a FreeText query, or an Inflectional query). If you are doing
a Contains query without wildcarding or the FormsOf(Inflectional type
queries you won't get stemming (although there are word breaker specific
some exceptions).
Hilary Cotter
Looking for a book on SQL Server replication?
http://www.nwsu.com/0974973602.html
"Phi!" <philgoogle2003@.yahoo.com> wrote in message
news:42d3fa28.0408120050.2b0d4d81@.posting.google.c om...
> Hello Hilary,
> Thankyou for you help, just to make sure, when I enable full text
> catalogs, does it index the text without stemming and stopping the
> data.
> By this i mean that is I had stored in the table "to be or not to be",
> would the full text catalog contain indexes for to, be, or and not or
> would it stem and stop the text.
> Again thankyou for your help
> Kind Regards
> Phil
> "Hilary Cotter" <hilaryk@.att.net> wrote in message
news:<#XtB1t5fEHA.1972@.TK2MSFTNGP09.phx.gbl>...[vbcol=seagreen]
|||Phi!
In addition to what Hilary says, there is another factor here and that is
the OS platform (Win2K vs. Win2003 or WinXP) that you have SQL Server
installed on. Specifically, the Windows 2000 Server (Win2K) wordbreaker -
infosoft.dll - indexes the "-" (dash or hyphen) in "7-UP" as one token,
i.e., as single phrase. A work around for this is to drop and re-create your
FT Catalog and use the Neutral "Language for Word Breaker" for the your
FT-enabled column. However, with the Neutral "Language for Word Breaker",
you will lose the formsof(inflectional) function as the words are "broken"
into tokens based upon the "white space" between words...
However, this is not the case with Windows Server 2003 (Win2003) or Windows
XP (WinXP) as these OS-platforms, ships with a newer (or better, i.e., more
expectant results) wordbreaker - langwrbk.dll which would correctly (or more
expectant results) break 7 and UP into separate tokens. So, in the long run
to get both the correct wordbreaking for you as well as the use of the
formsof(inflectional) function, if this is the functionality you're looking
for, you should consider upgrading to Win2003...
Regards,
John
"Hilary Cotter" <hilaryk@.att.net> wrote in message
news:u4tYhaGgEHA.1188@.TK2MSFTNGP11.phx.gbl...
> The answer is complex. First off to,be, or, and not are all noise words
and
> as such they would not be indexed.
> But to answer your question that depends on the word breaker. In general
> the words would be indexed as they appear in the content. For some word
> breakers different language rules dicate different indexing patterns, for
> instance in the French word breaker, marie-claire is indexed as two
> different words, marie and claire, however Marie-Claire is indexed as one
> word (MarieClaire). The hyphen and the capitalization cause it to be
indexed
> as one word not two.
> It is at query time when the search arguements might will be stemmed (when
> you are doing a FreeText query, or an Inflectional query). If you are
doing[vbcol=seagreen]
> a Contains query without wildcarding or the FormsOf(Inflectional type
> queries you won't get stemming (although there are word breaker specific
> some exceptions).
> --
> Hilary Cotter
> Looking for a book on SQL Server replication?
> http://www.nwsu.com/0974973602.html
>
> "Phi!" <philgoogle2003@.yahoo.com> wrote in message
> news:42d3fa28.0408120050.2b0d4d81@.posting.google.c om...
> news:<#XtB1t5fEHA.1972@.TK2MSFTNGP09.phx.gbl>...
it[vbcol=seagreen]
which[vbcol=seagreen]
(such[vbcol=seagreen]
indexes[vbcol=seagreen]
large
>
|||Hello Hillary,
AFter much testing we have decided to go as follows, we will use Full
Text catalogs and search using the contains keyword.
However to ensure SQL 2000 server does not do anything strange with
the results we have turned the lnaguage setting to neutral. We found
the results were not returned when we had the UK setting on. i.e.
"jpg" would not find "filename.jpg".
For wildcards we will use the LIKEkeyword as the contains does not do
patterm matching with wilcards but tries to find differenet words
instead.
Therefore we hope we have the best of both world, by the using the
contains in most cases but the the LIKE keyword whenever anyone needs
pattern matching (which should be rare).
Again thankyou for your hillary in helping me understanding full text
catlogs
Have a good weekend
Phil
"Hilary Cotter" <hilaryk@.att.net> wrote in message news:<u4tYhaGgEHA.1188@.TK2MSFTNGP11.phx.gbl>...[vbcol=seagreen]
> The answer is complex. First off to,be, or, and not are all noise words and
> as such they would not be indexed.
> But to answer your question that depends on the word breaker. In general
> the words would be indexed as they appear in the content. For some word
> breakers different language rules dicate different indexing patterns, for
> instance in the French word breaker, marie-claire is indexed as two
> different words, marie and claire, however Marie-Claire is indexed as one
> word (MarieClaire). The hyphen and the capitalization cause it to be indexed
> as one word not two.
> It is at query time when the search arguements might will be stemmed (when
> you are doing a FreeText query, or an Inflectional query). If you are doing
> a Contains query without wildcarding or the FormsOf(Inflectional type
> queries you won't get stemming (although there are word breaker specific
> some exceptions).
> --
> Hilary Cotter
> Looking for a book on SQL Server replication?
> http://www.nwsu.com/0974973602.html
>
> "Phi!" <philgoogle2003@.yahoo.com> wrote in message
> news:42d3fa28.0408120050.2b0d4d81@.posting.google.c om...
> news:<#XtB1t5fEHA.1972@.TK2MSFTNGP09.phx.gbl>...
|||Phi!,
Just FYI, if you were able to read my posting to this thread, you would of
understood why "the results were not returned when we had the UK setting on.
i.e. "jpg" would not find 'filename.jpg'" as it is a bug in the Win2K
wordbreaker dll and if in the future you decide to upgrade to Windows Server
2003 (Win2003) you would not of encountered this bug.
Regards,
John
"Phi!" <philgoogle2003@.yahoo.com> wrote in message
news:42d3fa28.0408130807.3fa93afe@.posting.google.c om...
> Hello Hillary,
> AFter much testing we have decided to go as follows, we will use Full
> Text catalogs and search using the contains keyword.
> However to ensure SQL 2000 server does not do anything strange with
> the results we have turned the lnaguage setting to neutral. We found
> the results were not returned when we had the UK setting on. i.e.
> "jpg" would not find "filename.jpg".
> For wildcards we will use the LIKEkeyword as the contains does not do
> patterm matching with wilcards but tries to find differenet words
> instead.
> Therefore we hope we have the best of both world, by the using the
> contains in most cases but the the LIKE keyword whenever anyone needs
> pattern matching (which should be rare).
> Again thankyou for your hillary in helping me understanding full text
> catlogs
> Have a good weekend
> Phil
>
> "Hilary Cotter" <hilaryk@.att.net> wrote in message
news:<u4tYhaGgEHA.1188@.TK2MSFTNGP11.phx.gbl>...[vbcol=seagreen]
and[vbcol=seagreen]
general[vbcol=seagreen]
for[vbcol=seagreen]
one[vbcol=seagreen]
indexed[vbcol=seagreen]
(when[vbcol=seagreen]
doing[vbcol=seagreen]
which it[vbcol=seagreen]
which[vbcol=seagreen]
(such[vbcol=seagreen]
a[vbcol=seagreen]
indexes[vbcol=seagreen]
large[vbcol=seagreen]
|||Hi John!
Thankyou for the tip, will bear it in mind when we upgrade.
I am having trouble getting an newsgroup reader on my desktop at work
(compnay ploicy etc) so have been limited to google at the moment so
did not know you had posted until today!
sorry for any confusion
Phil
"John Kane" <jt-kane@.comcast.net> wrote in message news:<O4zBxiagEHA.3632@.TK2MSFTNGP09.phx.gbl>...[vbcol=seagreen]
> Phi!,
> Just FYI, if you were able to read my posting to this thread, you would of
> understood why "the results were not returned when we had the UK setting on.
> i.e. "jpg" would not find 'filename.jpg'" as it is a bug in the Win2K
> wordbreaker dll and if in the future you decide to upgrade to Windows Server
> 2003 (Win2003) you would not of encountered this bug.
> Regards,
> John
>
>
> "Phi!" <philgoogle2003@.yahoo.com> wrote in message
> news:42d3fa28.0408130807.3fa93afe@.posting.google.c om...
> news:<u4tYhaGgEHA.1188@.TK2MSFTNGP11.phx.gbl>...
> and
> general
> for
> one
> indexed
> (when
> doing
> news:<#XtB1t5fEHA.1972@.TK2MSFTNGP09.phx.gbl>...
> which it
> which
> (such
> a
> indexes
> large
Monday, March 12, 2012
Fastest way to move XML document into and back out of CLR function
In SQL Server 2005 and Visual Studio 2005, what is the fastest way to pass
an xml data type variable into a C# CLR function and retrieve it back out of
the C# CLR function when the C# CLR function is done modifying it?
I tried this but get deployment error becuase SQLServer2005/CLR dotn support
System.Xml.XmlDocument:
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction]
public static int InsertSomeNode(System.Xml.XmlDocument pDoc)
{
//
return 1;
}
};
thorws error:
Error 1 Column, parameter, or variable #1: Cannot find data type
XmlDocument. InsertSomeNodeHi
the SQL XML datatype is a SqlXml type in the System.Data.SqlTypes namespace.
There is no .NET equivalent see
http://msdn2.microsoft.com/en-us/library/ms131092.aspx
John
"DR" wrote:
> Fastest way to move XML document into and back out of CLR function
> In SQL Server 2005 and Visual Studio 2005, what is the fastest way to pass
> an xml data type variable into a C# CLR function and retrieve it back out of
> the C# CLR function when the C# CLR function is done modifying it?
> I tried this but get deployment error becuase SQLServer2005/CLR dotn support
> System.Xml.XmlDocument:
> public partial class UserDefinedFunctions
> {
> [Microsoft.SqlServer.Server.SqlFunction]
> public static int InsertSomeNode(System.Xml.XmlDocument pDoc)
> {
> //
> return 1;
> }
> };
> thorws error:
> Error 1 Column, parameter, or variable #1: Cannot find data type
> XmlDocument. InsertSomeNode
>
>
Wednesday, March 7, 2012
Fast Way to Concat Records to Comma Sep VARCHAR
Here's a challenge.
If there is a 'one word' answer to this, i.e. the name of a built in
SQL Server function I can use, that would be great! However...
I have a standard 1:m relationship, e.g. tblHeader and tblDetail.
I want to create a view of records from 'tblHeader' and within that
view have a column (called e.g. DetailTypes) that provides a single
comma separated varchar of values from a varchar field (called e.g.
DetailType) that appears in related records in the 'tblDetail' table.
(hope you understood that :)
e.g. the contents of my 'tblDetail' table could be...
Detail ID | Header ID | DetailType
-----------
1 | 1 | A
2 | 1 | A
3 | 1 | B
4 | 2 | A
5 | 2 | C
6 | 3 | B
Therefore, the view I want to create should return:
Header ID | DetailTypes
----------
1 | 2A, 1B
2 | 1A, 1C
3 | 1B
i.e. the first row can be read as "Header 1 has 2 'A' detail records
and 1 'B' detail record."
I have created a view e.g. 'vqryHeaders' which calls a user defined
function that takes the HeaderID and opens a cursor on another view,
e.g. 'vqryDetailGrouped'. The other view groups the records in
tblDetail so that I can get a count of each DetailType for each Header
ID. The cursor then loops through the returned records concatenating
the count and detail type into a comma separated string (as shown
above).
However, when I run this across 20k records it is soooo sloooooww. I
have indexes on the relationship fields and I am using realistically
sized varchars - neither made any difference in speed. It is
definately the function that I wrote that slows it down as the view is
lightning fast when I remove my function call.
I can supply source code if necessary, but I think that this is a
kind-of generic problem so I don't see the point - yet.
I really hope you can help.
Regards,
Jezz"Jeremy Pridmore" <google.news@.pridmorej.freeserve.co.uk> wrote in message
news:9bce5a3f.0401190823.26a1bfe8@.posting.google.c om...
> Hi All,
> Here's a challenge.
> If there is a 'one word' answer to this, i.e. the name of a built in
> SQL Server function I can use, that would be great! However...
> I have a standard 1:m relationship, e.g. tblHeader and tblDetail.
> I want to create a view of records from 'tblHeader' and within that
> view have a column (called e.g. DetailTypes) that provides a single
> comma separated varchar of values from a varchar field (called e.g.
> DetailType) that appears in related records in the 'tblDetail' table.
> (hope you understood that :)
> e.g. the contents of my 'tblDetail' table could be...
> Detail ID | Header ID | DetailType
> -----------
> 1 | 1 | A
> 2 | 1 | A
> 3 | 1 | B
> 4 | 2 | A
> 5 | 2 | C
> 6 | 3 | B
> Therefore, the view I want to create should return:
> Header ID | DetailTypes
> ----------
> 1 | 2A, 1B
> 2 | 1A, 1C
> 3 | 1B
>
> i.e. the first row can be read as "Header 1 has 2 'A' detail records
> and 1 'B' detail record."
> I have created a view e.g. 'vqryHeaders' which calls a user defined
> function that takes the HeaderID and opens a cursor on another view,
> e.g. 'vqryDetailGrouped'. The other view groups the records in
> tblDetail so that I can get a count of each DetailType for each Header
> ID. The cursor then loops through the returned records concatenating
> the count and detail type into a comma separated string (as shown
> above).
> However, when I run this across 20k records it is soooo sloooooww. I
> have indexes on the relationship fields and I am using realistically
> sized varchars - neither made any difference in speed. It is
> definately the function that I wrote that slows it down as the view is
> lightning fast when I remove my function call.
> I can supply source code if necessary, but I think that this is a
> kind-of generic problem so I don't see the point - yet.
> I really hope you can help.
> Regards,
> Jezz
The fastest (and easiest) way would probably be in a front end application,
as this sort of thing is very awkward in pure SQL. You might find these
links useful for more information:
http://www.aspfaq.com/show.asp?id=2279
http://tinyurl.com/bib2
Simon|||The fastest way I know is to use the TSQL extension to the update
statement.
UPDATE table
SET @.var = col = expression which manipulates col
WHERE condition
I won't go into the details because it's rather lengthy and my wife is
waiting for me... I've included sample code and the output. -- Louis
------------------------
create table #H (headerID smallint)
insert into #H values(1)
insert into #H values(2)
insert into #H values(3)
create table #D (detailID smallint,headerID smallint,detailType
char(1))
insert into #D values(1,1,'A')
insert into #D values(2,1,'A')
insert into #D values(3,1,'B')
insert into #D values(4,2,'A')
insert into #D values(5,2,'C')
insert into #D values(6,3,'B')
select
d.headerid,
cast(count(d.detailtype) as varchar)+cast(detailtype as varchar) as
detailtypes,
identity(int,1,1) as i
into #T
from #H as h
join #D as d
on h.headerid=d.headerid
group by d.headerid,d.detailtype
order by d.headerid,d.detailtype
select headerid,identity(int,1,1) as i
into #Cursor
from #T
group by headerid order by headerid
declare @.i int, @.text varchar(8000)
set @.i=1
while exists(select * from #cursor where i=@.i) begin
set @.text=''
update #T
set @.text=detailtypes=@.text +',' + detailtypes
where headerid=(select headerid from #cursor where i=@.i)
set @.i=@.i+1
end
select a.headerid,right(detailtypes,len(detailtypes)-1) as detailtypes
from #T as a
join
(
select headerid,max(i) as i from #T group by headerid
) as b
on a.i=b.i
OUTPUT
headerid detailtypes
--- ------------------
1 2A,1B
2 1A,1C
3 1B|||>> I think that this is a kind-of generic problem .. <<
It is generic in the sense that newbies who don't understand what
First Normal Form (1NF) mean keep posting for a way to do front end
displays and reports in the SQL backend. This comes from not having
worked with a client/server architecture before, so you want to see
everything for the app written in one monolithic program.
The only safe way is to use a cursor and reutrn to slow, procedural
programming instead of declarative SQL programming. Any kludge you
use will not port to another SQL product, will run like glue and will
be almost unpredictable.|||joe.celko@.northface.edu (--CELKO--) wrote in message news:<a264e7ea.0401191731.47560540@.posting.google.com>...
> >> I think that this is a kind-of generic problem .. <<
> It is generic in the sense that newbies who don't understand what
> First Normal Form (1NF) mean keep posting for a way to do front end
> displays and reports in the SQL backend. This comes from not having
> worked with a client/server architecture before, so you want to see
> everything for the app written in one monolithic program.
> The only safe way is to use a cursor and reutrn to slow, procedural
> programming instead of declarative SQL programming. Any kludge you
> use will not port to another SQL product, will run like glue and will
> be almost unpredictable.
Thanks for confirming that the world still has some complete w@.nkers
in it.
1. Don't make assumptions. I'm not a newbie - as my post said I
already have an answer, albeit a slow one.
2. Don't make assumptions. I have worked on several successful C/S
apps.
3. Don't make assumptions. I don't necessarily want my app complied
into one large monolithic program. Also, If it is possible to create
a reusable function into which you can pass several parameters and get
a concatenated string, that procedure would be classed as 'generic'.
4. Don't make assumptions. I don't want it to port to any other
platform. Why do you think I posted in comp.databases.ms-sqlserver
and not in comp.databases?
I already have code that runs like glue, which is why I posted. I
would expect any *intelligent* person to give a reasonable response
(such as Louis) - not a rant.
Although an appropriate procedure can be created in 'front-end' code -
in my case i'm using vbscript (more fuel?), I would expect that
varchar 'lookup' and manipulation in the database would be quicker
than having to retrieve all the data into the front end and process it
there.
Oh, and lets not forget the most inportant thing - the reason why I
want to do this! It will give me a searchable field in a view to
which I can apply my 'generic' filtering procedures.
So, how is your snow coming along?
"You're not much use to me alive are you" CELKO?
- Bricktop.
La, la, la - I'm ignoring you now.
What was that? Whatever.|||louisducnguyen@.hotmail.com (louis nguyen) wrote in message news:<b0e9d53.0401191541.34c5bf22@.posting.google.com>...
> The fastest way I know is to use the TSQL extension to the update
> statement.
> UPDATE table
> SET @.var = col = expression which manipulates col
> WHERE condition
> I won't go into the details because it's rather lengthy and my wife is
> waiting for me... I've included sample code and the output. -- Louis
<snip
Thanks Louis - you reminded me about temporary tables. That will go
along way in helping me - my problem probably lays with the fact that
I want to return this concatenated field in a view - not in a stored
proc, so the only way i can think of doing it is to use a function
that it aliased and pass in the primary key, select the records i need
in the function and then concatenate them.
Thanks again,
Jeremy|||Jeremy Pridmore (google.news@.pridmorej.freeserve.co.uk) writes:
> louisducnguyen@.hotmail.com (louis nguyen) wrote in message
news:<b0e9d53.0401191541.34c5bf22@.posting.google.com>...
>> The fastest way I know is to use the TSQL extension to the update
>> statement.
>> UPDATE table
>> SET @.var = col = expression which manipulates col
>> WHERE condition
>>
>> I won't go into the details because it's rather lengthy and my wife is
>> waiting for me... I've included sample code and the output. -- Louis
>>
><snip>
> Thanks Louis - you reminded me about temporary tables. That will go
> along way in helping me - my problem probably lays with the fact that
> I want to return this concatenated field in a view - not in a stored
> proc, so the only way i can think of doing it is to use a function
> that it aliased and pass in the primary key, select the records i need
> in the function and then concatenate them.
Beware that any "fast" solution to your problem will rely on
undocumented and undefined behaviour. The only safe way to this
in SQL is to it with a cursor or some other iterative method.
--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||>> The fastest way I know is to use the TSQL extension to the update
>> statement.
>> UPDATE table
>> SET @.var = col = expression which manipulates col
>> WHERE condition
>
Erland:
>Beware that any "fast" solution to your problem will rely on
>undocumented and undefined behaviour. The only safe way to this
>in SQL is to it with a cursor or some other iterative method.
Erland - are you referring to the code above here? What do you mean
exactly? Is there some sneakiness of undocumented goodness you are
keeping from us?|||I'll admit the code I posted is not standard sql. The extension to
the UPDATE statement is written about in Inside SQL Server 7.0 in the
brain teasers section. It was used to calculate running totals.|||WangKhar (Wangkhar@.yahoo.com) writes:
> Erland - are you referring to the code above here? What do you mean
> exactly? Is there some sneakiness of undocumented goodness you are
> keeping from us?
No, the problem is that you have no guarantee that the code will always
produce the expected result. A change of query plan or whatever. Could
break with the next service pack.
Here is a KB article on a similar trick. Pay particular attention to
first paragraph under CAUSE:
http://support.microsoft.com/default.aspx?scid=287515.
--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Thats interesting, thanks.
Erland Sommarskog <sommar@.algonet.se> wrote in message news:<Xns94786FEB7DBEYazorman@.127.0.0.1>...
> WangKhar (Wangkhar@.yahoo.com) writes:
> > Erland - are you referring to the code above here? What do you mean
> > exactly? Is there some sneakiness of undocumented goodness you are
> > keeping from us?
> No, the problem is that you have no guarantee that the code will always
> produce the expected result. A change of query plan or whatever. Could
> break with the next service pack.
> Here is a KB article on a similar trick. Pay particular attention to
> first paragraph under CAUSE:
> http://support.microsoft.com/default.aspx?scid=287515.|||Does this help:
http://www.sqlteam.com/item.asp?ItemID=2368
"Jeremy Pridmore" <google.news@.pridmorej.freeserve.co.uk> wrote in message
news:9bce5a3f.0401190823.26a1bfe8@.posting.google.c om...
> Hi All,
> Here's a challenge.
> If there is a 'one word' answer to this, i.e. the name of a built in
> SQL Server function I can use, that would be great! However...
> I have a standard 1:m relationship, e.g. tblHeader and tblDetail.
> I want to create a view of records from 'tblHeader' and within that
> view have a column (called e.g. DetailTypes) that provides a single
> comma separated varchar of values from a varchar field (called e.g.
> DetailType) that appears in related records in the 'tblDetail' table.
> (hope you understood that :)
> e.g. the contents of my 'tblDetail' table could be...
> Detail ID | Header ID | DetailType
> -----------
> 1 | 1 | A
> 2 | 1 | A
> 3 | 1 | B
> 4 | 2 | A
> 5 | 2 | C
> 6 | 3 | B
> Therefore, the view I want to create should return:
> Header ID | DetailTypes
> ----------
> 1 | 2A, 1B
> 2 | 1A, 1C
> 3 | 1B
>
> i.e. the first row can be read as "Header 1 has 2 'A' detail records
> and 1 'B' detail record."
> I have created a view e.g. 'vqryHeaders' which calls a user defined
> function that takes the HeaderID and opens a cursor on another view,
> e.g. 'vqryDetailGrouped'. The other view groups the records in
> tblDetail so that I can get a count of each DetailType for each Header
> ID. The cursor then loops through the returned records concatenating
> the count and detail type into a comma separated string (as shown
> above).
> However, when I run this across 20k records it is soooo sloooooww. I
> have indexes on the relationship fields and I am using realistically
> sized varchars - neither made any difference in speed. It is
> definately the function that I wrote that slows it down as the view is
> lightning fast when I remove my function call.
> I can supply source code if necessary, but I think that this is a
> kind-of generic problem so I don't see the point - yet.
> I really hope you can help.
> Regards,
> Jezz
Sunday, February 26, 2012
Fast counting of records
can retrieve a count of the last recordset you opened.
For example:
I've got a stored procedure that returns a recordset using the TOP 10
so I only get the top 10 records. I need to know the recordcount but I
dont want to reuse the SELECT statement because its quite complex.
Any ideas?
What does @.@.Count do?
Thanks in advance"Samuel Hon" <noreply@.samuelhon.co.uk> wrote in message
news:c8672b7d.0309110815.2fba8c32@.posting.google.c om...
> I seem to remember reading many moons ago about a function where you
> can retrieve a count of the last recordset you opened.
> For example:
> I've got a stored procedure that returns a recordset using the TOP 10
> so I only get the top 10 records. I need to know the recordcount but I
> dont want to reuse the SELECT statement because its quite complex.
> Any ideas?
> What does @.@.Count do?
> Thanks in advance
@.@.ROWCOUNT
Simon
Sunday, February 19, 2012
Failure adding a new partition range to a partition function.
I'll start off with the definitions of existing objects, but in summary, I'm
attempting to add a new range to a partition function, and expect this to be
an almost instantaneous operation, but it is not (and, at the moment, I can't
get it to complete at all).
The partition scheme started off with two groups:
CREATE PARTITION SCHEME [schemePartitonFile] AS PARTITION [fnPartitionFile]
TO ([MeterGroup1], [MeterGroup2])
We have managed to fill the second group (MeterGroup2) (poor planning), and
so need to add a new partition.
MeterGroup2 was specified not to grow past (the size of the LUN it was on -
0.5GB).
The partition function we are using is based on a FileID (FID), and is
currently defined as:
CREATE PARTITION FUNCTION [fnPartitionFile](int) AS RANGE LEFT FOR VALUES
(8000)
So, all files < 8000 go into MeterGroup1, and all Files >= 8000 go into
meter group 2.
There are four tables using the scheme - for example:
CREATE TABLE [dbo].[tbReadIntDevDtl](
[FID] [int] NOT NULL,
[Block] [smallint] NOT NULL,
[Period] [tinyint] NOT NULL,
[IntervalValue] [int] NOT NULL,
[Quality] [char](1) NOT NULL,
CONSTRAINT [PK_tbReadIntDevDtl] PRIMARY KEY CLUSTERED
(
[FID] ASC,
[Block] ASC,
[Period] ASC
)ON [schemePartitonFile]([FID])
)
So with MeterGroup2 filled, we would like to add a new group to the
partition scheme, and direct all new files to that group.
Checked the current max FID: 31976
What we expect to be able to do is:
ALTER PARTITION SCHEME schemePartitonFile NEXT USED MeterGroup3
...followed by...
ALTER PARTITION FUNCTION fnPartitionFile() SPLIT RANGE (31977)
Given that the current max FID is 31976, we would expect to be able to run
the alter partition function statement, and it would not need to do any
physical movement of data, and should complete pretty much instantly,
resulting in the following scheme...
FID < 8000 in Partition 1
FID >= 8000 AND FID < 31977 in Partition 2
FID >= 31977 in Partition 3
At first, I immediately got the following error:
Could not allocate space for object
'dbo.tbReadIntDevDtl'.'PK_tbReadIntDevDtl' in database 'SageEMS' because the
'MeterGroup2' filegroup is full. Create disk space by deleting unneeded
files, dropping objects in the filegroup, adding additional files to the
filegroup, or setting autogrowth on for existing files in the filegroup.
I increased the size of MeterGroup2 to use the 0.5GB of free space on the
LUN, and then the process would run for around 45 minutes, then start rolling
back, ending with an error that the database was out of log.
I increased the log from 15GB to 36GB, and now the process runs for around
45 minutes before rolling back, and ends with the same error that we got at
first - can't increase space in MeterGroup2.
To verify that my understanding of the process of splitting partitions is
correct, I created a new scheme, a new function, and a new copy of the table
in question - identical to existing scheme/function/table in structure.
I then put in the first and last 1000 rows for each range (e.g. top 1000 *
order by FID asc where FID < 8000, then top 1000 * order by FID desc where
FID < 8000, followed by top 1000 * order by FID asc where FID >= 8000 and top
1000 * order by FID desc where FID >= 8000.
As expected, this indicates 2000 rows in each of the two partitions.
Splitting the new partition, and checking the rows shows (as expected) 2000
rows in the first two partitions, and none in the third.
select index_id, partition_number, rows
from sys.partitions
where object_id = object_id('tbReadIntDevDtl')
index_id partition_number rows
-- -- --
1 1 2000
1 2 2000
1 3 0
What could be causing this issue. Have I got something fundamentally wrong
in my understanding of how RANGE SPLIT works?
Thanks
Bernard
P.S. Please, no answers suggesting I should switch partitions, because that
isn't what I'm trying to do. We will switch older partitions out, but here
we simply want to direct new records into a new partition.> Given that the current max FID is 31976, we would expect to be able to run
> the alter partition function statement, and it would not need to do any
> physical movement of data, and should complete pretty much instantly,
> resulting in the following scheme...
No, what you need to do is to always have an empty partition "at the end". And when you want to
split, you split so you have two empty partitions. I.e., there will be no data movement when you
split one empty partition into two empty partitions. Same basic principle goes for when you purge
data (if you are going to do that). In other words, never populate your "unbound"/"edge" partitions.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Bernard Sheppard" <BernardSheppard@.discussions.microsoft.com> wrote in message
news:C9A212E7-1A8D-4054-81C5-4E2DA6214025@.microsoft.com...
> Long Post (so you know what I've already tried).
> I'll start off with the definitions of existing objects, but in summary, I'm
> attempting to add a new range to a partition function, and expect this to be
> an almost instantaneous operation, but it is not (and, at the moment, I can't
> get it to complete at all).
> The partition scheme started off with two groups:
> CREATE PARTITION SCHEME [schemePartitonFile] AS PARTITION [fnPartitionFile]
> TO ([MeterGroup1], [MeterGroup2])
> We have managed to fill the second group (MeterGroup2) (poor planning), and
> so need to add a new partition.
> MeterGroup2 was specified not to grow past (the size of the LUN it was on -
> 0.5GB).
> The partition function we are using is based on a FileID (FID), and is
> currently defined as:
> CREATE PARTITION FUNCTION [fnPartitionFile](int) AS RANGE LEFT FOR VALUES
> (8000)
> So, all files < 8000 go into MeterGroup1, and all Files >= 8000 go into
> meter group 2.
> There are four tables using the scheme - for example:
> CREATE TABLE [dbo].[tbReadIntDevDtl](
> [FID] [int] NOT NULL,
> [Block] [smallint] NOT NULL,
> [Period] [tinyint] NOT NULL,
> [IntervalValue] [int] NOT NULL,
> [Quality] [char](1) NOT NULL,
> CONSTRAINT [PK_tbReadIntDevDtl] PRIMARY KEY CLUSTERED
> (
> [FID] ASC,
> [Block] ASC,
> [Period] ASC
> )ON [schemePartitonFile]([FID])
> )
> So with MeterGroup2 filled, we would like to add a new group to the
> partition scheme, and direct all new files to that group.
> Checked the current max FID: 31976
> What we expect to be able to do is:
> ALTER PARTITION SCHEME schemePartitonFile NEXT USED MeterGroup3
> ...followed by...
> ALTER PARTITION FUNCTION fnPartitionFile() SPLIT RANGE (31977)
> Given that the current max FID is 31976, we would expect to be able to run
> the alter partition function statement, and it would not need to do any
> physical movement of data, and should complete pretty much instantly,
> resulting in the following scheme...
> FID < 8000 in Partition 1
> FID >= 8000 AND FID < 31977 in Partition 2
> FID >= 31977 in Partition 3
> At first, I immediately got the following error:
> Could not allocate space for object
> 'dbo.tbReadIntDevDtl'.'PK_tbReadIntDevDtl' in database 'SageEMS' because the
> 'MeterGroup2' filegroup is full. Create disk space by deleting unneeded
> files, dropping objects in the filegroup, adding additional files to the
> filegroup, or setting autogrowth on for existing files in the filegroup.
> I increased the size of MeterGroup2 to use the 0.5GB of free space on the
> LUN, and then the process would run for around 45 minutes, then start rolling
> back, ending with an error that the database was out of log.
> I increased the log from 15GB to 36GB, and now the process runs for around
> 45 minutes before rolling back, and ends with the same error that we got at
> first - can't increase space in MeterGroup2.
> To verify that my understanding of the process of splitting partitions is
> correct, I created a new scheme, a new function, and a new copy of the table
> in question - identical to existing scheme/function/table in structure.
> I then put in the first and last 1000 rows for each range (e.g. top 1000 *
> order by FID asc where FID < 8000, then top 1000 * order by FID desc where
> FID < 8000, followed by top 1000 * order by FID asc where FID >= 8000 and top
> 1000 * order by FID desc where FID >= 8000.
> As expected, this indicates 2000 rows in each of the two partitions.
> Splitting the new partition, and checking the rows shows (as expected) 2000
> rows in the first two partitions, and none in the third.
> select index_id, partition_number, rows
> from sys.partitions
> where object_id = object_id('tbReadIntDevDtl')
> index_id partition_number rows
> -- -- --
> 1 1 2000
> 1 2 2000
> 1 3 0
> What could be causing this issue. Have I got something fundamentally wrong
> in my understanding of how RANGE SPLIT works?
> Thanks
> Bernard
> P.S. Please, no answers suggesting I should switch partitions, because that
> isn't what I'm trying to do. We will switch older partitions out, but here
> we simply want to direct new records into a new partition.|||Beranrd
Check out this great article
http://www.simple-talk.com/sql/sql-server-2005/partitioned-tables-in-sql-server-2005/
"Bernard Sheppard" <BernardSheppard@.discussions.microsoft.com> wrote in
message news:C9A212E7-1A8D-4054-81C5-4E2DA6214025@.microsoft.com...
> Long Post (so you know what I've already tried).
> I'll start off with the definitions of existing objects, but in summary,
> I'm
> attempting to add a new range to a partition function, and expect this to
> be
> an almost instantaneous operation, but it is not (and, at the moment, I
> can't
> get it to complete at all).
> The partition scheme started off with two groups:
> CREATE PARTITION SCHEME [schemePartitonFile] AS PARTITION
> [fnPartitionFile]
> TO ([MeterGroup1], [MeterGroup2])
> We have managed to fill the second group (MeterGroup2) (poor planning),
> and
> so need to add a new partition.
> MeterGroup2 was specified not to grow past (the size of the LUN it was
> on -
> 0.5GB).
> The partition function we are using is based on a FileID (FID), and is
> currently defined as:
> CREATE PARTITION FUNCTION [fnPartitionFile](int) AS RANGE LEFT FOR VALUES
> (8000)
> So, all files < 8000 go into MeterGroup1, and all Files >= 8000 go into
> meter group 2.
> There are four tables using the scheme - for example:
> CREATE TABLE [dbo].[tbReadIntDevDtl](
> [FID] [int] NOT NULL,
> [Block] [smallint] NOT NULL,
> [Period] [tinyint] NOT NULL,
> [IntervalValue] [int] NOT NULL,
> [Quality] [char](1) NOT NULL,
> CONSTRAINT [PK_tbReadIntDevDtl] PRIMARY KEY CLUSTERED
> (
> [FID] ASC,
> [Block] ASC,
> [Period] ASC
> )ON [schemePartitonFile]([FID])
> )
> So with MeterGroup2 filled, we would like to add a new group to the
> partition scheme, and direct all new files to that group.
> Checked the current max FID: 31976
> What we expect to be able to do is:
> ALTER PARTITION SCHEME schemePartitonFile NEXT USED MeterGroup3
> ...followed by...
> ALTER PARTITION FUNCTION fnPartitionFile() SPLIT RANGE (31977)
> Given that the current max FID is 31976, we would expect to be able to run
> the alter partition function statement, and it would not need to do any
> physical movement of data, and should complete pretty much instantly,
> resulting in the following scheme...
> FID < 8000 in Partition 1
> FID >= 8000 AND FID < 31977 in Partition 2
> FID >= 31977 in Partition 3
> At first, I immediately got the following error:
> Could not allocate space for object
> 'dbo.tbReadIntDevDtl'.'PK_tbReadIntDevDtl' in database 'SageEMS' because
> the
> 'MeterGroup2' filegroup is full. Create disk space by deleting unneeded
> files, dropping objects in the filegroup, adding additional files to the
> filegroup, or setting autogrowth on for existing files in the filegroup.
> I increased the size of MeterGroup2 to use the 0.5GB of free space on the
> LUN, and then the process would run for around 45 minutes, then start
> rolling
> back, ending with an error that the database was out of log.
> I increased the log from 15GB to 36GB, and now the process runs for around
> 45 minutes before rolling back, and ends with the same error that we got
> at
> first - can't increase space in MeterGroup2.
> To verify that my understanding of the process of splitting partitions is
> correct, I created a new scheme, a new function, and a new copy of the
> table
> in question - identical to existing scheme/function/table in structure.
> I then put in the first and last 1000 rows for each range (e.g. top 1000 *
> order by FID asc where FID < 8000, then top 1000 * order by FID desc where
> FID < 8000, followed by top 1000 * order by FID asc where FID >= 8000 and
> top
> 1000 * order by FID desc where FID >= 8000.
> As expected, this indicates 2000 rows in each of the two partitions.
> Splitting the new partition, and checking the rows shows (as expected)
> 2000
> rows in the first two partitions, and none in the third.
> select index_id, partition_number, rows
> from sys.partitions
> where object_id = object_id('tbReadIntDevDtl')
> index_id partition_number rows
> -- -- --
> 1 1 2000
> 1 2 2000
> 1 3 0
> What could be causing this issue. Have I got something fundamentally
> wrong
> in my understanding of how RANGE SPLIT works?
> Thanks
> Bernard
> P.S. Please, no answers suggesting I should switch partitions, because
> that
> isn't what I'm trying to do. We will switch older partitions out, but
> here
> we simply want to direct new records into a new partition.|||Thanks for the reply, Tibor.
That leads to a couple of follow up questions:
With RANGE LEFT, it would appear that the edge partition can't ever have
data (if I want to be able to quickly change ranges), which means that I
can't have a strategy where I fill an edge partition until full, and then
create a new partition and adjust the ranges so new data flows into it.
This is the strategy that I would like to use: we want to be able to load
data into "bucket" (last partition) where we always fill the last bucket
until (nearly) full, then start filling the next bucket. Each bucket is
sized to hold a reasonable amount of data (around 1 billion rows, or
thereabouts), but we can't accurately predict when we will fill a bucket.
We will eventually switch out then delete old data (once it is 7 years after
it was loaded) - but our date partitioning is less to do with the date that
the data is for, and more to do with the date it was loaded.
Any suggestions?
Thanks
"Tibor Karaszi" wrote:
> No, what you need to do is to always have an empty partition "at the end". And when you want to
> split, you split so you have two empty partitions. I.e., there will be no data movement when you
> split one empty partition into two empty partitions. Same basic principle goes for when you purge
> data (if you are going to do that). In other words, never populate your "unbound"/"edge" partitions.
>|||I'm not sure I follow you, Bernard...
> With RANGE LEFT, it would appear that the edge partition can't ever have
> data (if I want to be able to quickly change ranges), which means that I
> can't have a strategy where I fill an edge partition until full
This is what I have problems with. How can you say "until full" for something which is unrestricted?
I assume that the values you add (what you are partitioning over) are either increasing or
decreasing. Otherwise, you wouldn't know that they go to the "last" or "first" partition. I also
assume that they are restricted in some sense, else you wouldn't be able to do a SPLIT later on.
Based on above, it seems that the values might as well go into a predefined unrestricted partition.
But perhaps it is just me being dense (wouldn't be the first time ;-) ).
To the best of my knowledge, the partition that you SPLIT or partitions that you MERGE need to be
empty to ensure meta-data only operations.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Bernard Sheppard" <BernardSheppard@.discussions.microsoft.com> wrote in message
news:DF45FCAC-2A4B-4481-927C-A17485CEC65C@.microsoft.com...
> Thanks for the reply, Tibor.
> That leads to a couple of follow up questions:
> With RANGE LEFT, it would appear that the edge partition can't ever have
> data (if I want to be able to quickly change ranges), which means that I
> can't have a strategy where I fill an edge partition until full, and then
> create a new partition and adjust the ranges so new data flows into it.
> This is the strategy that I would like to use: we want to be able to load
> data into "bucket" (last partition) where we always fill the last bucket
> until (nearly) full, then start filling the next bucket. Each bucket is
> sized to hold a reasonable amount of data (around 1 billion rows, or
> thereabouts), but we can't accurately predict when we will fill a bucket.
> We will eventually switch out then delete old data (once it is 7 years after
> it was loaded) - but our date partitioning is less to do with the date that
> the data is for, and more to do with the date it was loaded.
> Any suggestions?
> Thanks
>
> "Tibor Karaszi" wrote:
>
>> No, what you need to do is to always have an empty partition "at the end". And when you want to
>> split, you split so you have two empty partitions. I.e., there will be no data movement when you
>> split one empty partition into two empty partitions. Same basic principle goes for when you purge
>> data (if you are going to do that). In other words, never populate your "unbound"/"edge"
>> partitions.
>|||> With RANGE LEFT, it would appear that the edge partition can't ever have
> data (if I want to be able to quickly change ranges), which means that I
> can't have a strategy where I fill an edge partition until full, and then
> create a new partition and adjust the ranges so new data flows into it.
Regardless of the RANGE specification, you have the same issue. Like Tibor
mentioned, if you want to split a partition without data movement, plan so
that the last partition is always empty.
> This is the strategy that I would like to use: we want to be able to load
> data into "bucket" (last partition) where we always fill the last bucket
> until (nearly) full, then start filling the next bucket. Each bucket is
> sized to hold a reasonable amount of data (around 1 billion rows, or
> thereabouts), but we can't accurately predict when we will fill a bucket.
For a sliding window, I suggest you create your partition function to allow
for 2 empty (n and n - 1) partitions. Once you start filling the second
from last one (n - 1), split the last partition (n, which is still empty) to
prepare for the next time around. When you are ready to delete/archive the
oldest partition, simply switch out the first partition and merge it with
the second.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Bernard Sheppard" <BernardSheppard@.discussions.microsoft.com> wrote in
message news:DF45FCAC-2A4B-4481-927C-A17485CEC65C@.microsoft.com...
> Thanks for the reply, Tibor.
> That leads to a couple of follow up questions:
> With RANGE LEFT, it would appear that the edge partition can't ever have
> data (if I want to be able to quickly change ranges), which means that I
> can't have a strategy where I fill an edge partition until full, and then
> create a new partition and adjust the ranges so new data flows into it.
> This is the strategy that I would like to use: we want to be able to load
> data into "bucket" (last partition) where we always fill the last bucket
> until (nearly) full, then start filling the next bucket. Each bucket is
> sized to hold a reasonable amount of data (around 1 billion rows, or
> thereabouts), but we can't accurately predict when we will fill a bucket.
> We will eventually switch out then delete old data (once it is 7 years
> after
> it was loaded) - but our date partitioning is less to do with the date
> that
> the data is for, and more to do with the date it was loaded.
> Any suggestions?
> Thanks
>
> "Tibor Karaszi" wrote:
>
>> No, what you need to do is to always have an empty partition "at the
>> end". And when you want to
>> split, you split so you have two empty partitions. I.e., there will be no
>> data movement when you
>> split one empty partition into two empty partitions. Same basic principle
>> goes for when you purge
>> data (if you are going to do that). In other words, never populate your
>> "unbound"/"edge" partitions.
>|||Hi Tibor, thanks, you've answered my question (with your very last statement).
Cheers.
"Tibor Karaszi" wrote:
> I'm not sure I follow you, Bernard...
>
> > With RANGE LEFT, it would appear that the edge partition can't ever have
> > data (if I want to be able to quickly change ranges), which means that I
> > can't have a strategy where I fill an edge partition until full
> This is what I have problems with. How can you say "until full" for something which is unrestricted?
>
Physically full - each partition will (almost) fill a mounted disk (a SAN
LUN). Whilst I could distribute a filegroup across multiple LUNs, it makes
for more difficult management, and makes life more difficult for piecemeal
restores. If I can stick with a single filegroup per LUN, then my
file/filegroup/partitioning strategy can be automated.
I'm partitioning for a few reasons - recoverability, ability to archive
(read delete, or alternatively move to slow storage (e.g. read only on NTFS
compression), ability to restore subsets of data (e.g. just data loaded in
the last x month) into other environments, etc, ability to utilise multiple
LUNs on a SAN for maximum parallelism, etc.
My main table will grow to several terabytes and hundreds of billions of
rows. Distributing this (evenly) over many small LUNs will allow maintenance
activities such as backup, restore, integrity checks, etc to run at maximum
speed.
I used to use DPVs on SQL Server 2000.
> I assume that the values you add (what you are partitioning over) are either increasing or
> decreasing. Otherwise, you wouldn't know that they go to the "last" or "first" partition. I also
> assume that they are restricted in some sense, else you wouldn't be able to do a SPLIT later on.
>
Absolutely correct. My raw value that I am partitioning over is an identity
column that relates the data back to the batch in which it was recieved -
this ID is then used as part of the PK (and partition scheme input) for the
lower level data.
This means that I am only ever inserting into the last partition (and, for
that matter, physically in order due to the clustered index).
> Based on above, it seems that the values might as well go into a predefined unrestricted partition.
> But perhaps it is just me being dense (wouldn't be the first time ;-) ).
Yes, except I then can't partition across (fixed) size LUNSs.
> To the best of my knowledge, the partition that you SPLIT or partitions
that you MERGE need to be
> empty to ensure meta-data only operations.
That has hit the nail on the head, and tests I've done have confirmed this.
I've read (and re-read) BOL, and whilst it does describe where the new range
value goes (e.g. on LEFT, becomes part of the new partition), and it
indicates that if you split an existing range, data that falls into the new
range gets moved, it doesn't seem to state (at least clearly enough for me to
tell) that, even if there is no data at the split point, if there is any data
in the partition being split, it is not a meta-data only operation.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
Failure adding a new partition range to a partition function.
I'll start off with the definitions of existing objects, but in summary, I'm
attempting to add a new range to a partition function, and expect this to be
an almost instantaneous operation, but it is not (and, at the moment, I can't
get it to complete at all).
The partition scheme started off with two groups:
CREATE PARTITION SCHEME [schemePartitonFile] AS PARTITION [fnPartitionFile]
TO ([MeterGroup1], [MeterGroup2])
We have managed to fill the second group (MeterGroup2) (poor planning), and
so need to add a new partition.
MeterGroup2 was specified not to grow past (the size of the LUN it was on -
0.5GB).
The partition function we are using is based on a FileID (FID), and is
currently defined as:
CREATE PARTITION FUNCTION [fnPartitionFile](int) AS RANGE LEFT FOR VALUES
(8000)
So, all files < 8000 go into MeterGroup1, and all Files >= 8000 go into
meter group 2.
There are four tables using the scheme - for example:
CREATE TABLE [dbo].[tbReadIntDevDtl](
[FID] [int] NOT NULL,
[Block] [smallint] NOT NULL,
[Period] [tinyint] NOT NULL,
[IntervalValue] [int] NOT NULL,
[Quality] [char](1) NOT NULL,
CONSTRAINT [PK_tbReadIntDevDtl] PRIMARY KEY CLUSTERED
(
[FID] ASC,
[Block] ASC,
[Period] ASC
)ON [schemePartitonFile]([FID])
)
So with MeterGroup2 filled, we would like to add a new group to the
partition scheme, and direct all new files to that group.
Checked the current max FID: 31976
What we expect to be able to do is:
ALTER PARTITION SCHEME schemePartitonFile NEXT USED MeterGroup3
...followed by...
ALTER PARTITION FUNCTION fnPartitionFile() SPLIT RANGE (31977)
Given that the current max FID is 31976, we would expect to be able to run
the alter partition function statement, and it would not need to do any
physical movement of data, and should complete pretty much instantly,
resulting in the following scheme...
FID < 8000 in Partition 1
FID >= 8000 AND FID < 31977 in Partition 2
FID >= 31977 in Partition 3
At first, I immediately got the following error:
Could not allocate space for object
'dbo.tbReadIntDevDtl'.'PK_tbReadIntDevDtl' in database 'SageEMS' because the
'MeterGroup2' filegroup is full. Create disk space by deleting unneeded
files, dropping objects in the filegroup, adding additional files to the
filegroup, or setting autogrowth on for existing files in the filegroup.
I increased the size of MeterGroup2 to use the 0.5GB of free space on the
LUN, and then the process would run for around 45 minutes, then start rolling
back, ending with an error that the database was out of log.
I increased the log from 15GB to 36GB, and now the process runs for around
45 minutes before rolling back, and ends with the same error that we got at
first - can't increase space in MeterGroup2.
To verify that my understanding of the process of splitting partitions is
correct, I created a new scheme, a new function, and a new copy of the table
in question - identical to existing scheme/function/table in structure.
I then put in the first and last 1000 rows for each range (e.g. top 1000 *
order by FID asc where FID < 8000, then top 1000 * order by FID desc where
FID < 8000, followed by top 1000 * order by FID asc where FID >= 8000 and top
1000 * order by FID desc where FID >= 8000.
As expected, this indicates 2000 rows in each of the two partitions.
Splitting the new partition, and checking the rows shows (as expected) 2000
rows in the first two partitions, and none in the third.
select index_id, partition_number, rows
from sys.partitions
where object_id = object_id('tbReadIntDevDtl')
index_id partition_number rows
-- -- --
1 1 2000
1 2 2000
1 3 0
What could be causing this issue. Have I got something fundamentally wrong
in my understanding of how RANGE SPLIT works?
Thanks
Bernard
P.S. Please, no answers suggesting I should switch partitions, because that
isn't what I'm trying to do. We will switch older partitions out, but here
we simply want to direct new records into a new partition.
> Given that the current max FID is 31976, we would expect to be able to run
> the alter partition function statement, and it would not need to do any
> physical movement of data, and should complete pretty much instantly,
> resulting in the following scheme...
No, what you need to do is to always have an empty partition "at the end". And when you want to
split, you split so you have two empty partitions. I.e., there will be no data movement when you
split one empty partition into two empty partitions. Same basic principle goes for when you purge
data (if you are going to do that). In other words, never populate your "unbound"/"edge" partitions.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Bernard Sheppard" <BernardSheppard@.discussions.microsoft.com> wrote in message
news:C9A212E7-1A8D-4054-81C5-4E2DA6214025@.microsoft.com...
> Long Post (so you know what I've already tried).
> I'll start off with the definitions of existing objects, but in summary, I'm
> attempting to add a new range to a partition function, and expect this to be
> an almost instantaneous operation, but it is not (and, at the moment, I can't
> get it to complete at all).
> The partition scheme started off with two groups:
> CREATE PARTITION SCHEME [schemePartitonFile] AS PARTITION [fnPartitionFile]
> TO ([MeterGroup1], [MeterGroup2])
> We have managed to fill the second group (MeterGroup2) (poor planning), and
> so need to add a new partition.
> MeterGroup2 was specified not to grow past (the size of the LUN it was on -
> 0.5GB).
> The partition function we are using is based on a FileID (FID), and is
> currently defined as:
> CREATE PARTITION FUNCTION [fnPartitionFile](int) AS RANGE LEFT FOR VALUES
> (8000)
> So, all files < 8000 go into MeterGroup1, and all Files >= 8000 go into
> meter group 2.
> There are four tables using the scheme - for example:
> CREATE TABLE [dbo].[tbReadIntDevDtl](
> [FID] [int] NOT NULL,
> [Block] [smallint] NOT NULL,
> [Period] [tinyint] NOT NULL,
> [IntervalValue] [int] NOT NULL,
> [Quality] [char](1) NOT NULL,
> CONSTRAINT [PK_tbReadIntDevDtl] PRIMARY KEY CLUSTERED
> (
> [FID] ASC,
> [Block] ASC,
> [Period] ASC
> )ON [schemePartitonFile]([FID])
> )
> So with MeterGroup2 filled, we would like to add a new group to the
> partition scheme, and direct all new files to that group.
> Checked the current max FID: 31976
> What we expect to be able to do is:
> ALTER PARTITION SCHEME schemePartitonFile NEXT USED MeterGroup3
> ...followed by...
> ALTER PARTITION FUNCTION fnPartitionFile() SPLIT RANGE (31977)
> Given that the current max FID is 31976, we would expect to be able to run
> the alter partition function statement, and it would not need to do any
> physical movement of data, and should complete pretty much instantly,
> resulting in the following scheme...
> FID < 8000 in Partition 1
> FID >= 8000 AND FID < 31977 in Partition 2
> FID >= 31977 in Partition 3
> At first, I immediately got the following error:
> Could not allocate space for object
> 'dbo.tbReadIntDevDtl'.'PK_tbReadIntDevDtl' in database 'SageEMS' because the
> 'MeterGroup2' filegroup is full. Create disk space by deleting unneeded
> files, dropping objects in the filegroup, adding additional files to the
> filegroup, or setting autogrowth on for existing files in the filegroup.
> I increased the size of MeterGroup2 to use the 0.5GB of free space on the
> LUN, and then the process would run for around 45 minutes, then start rolling
> back, ending with an error that the database was out of log.
> I increased the log from 15GB to 36GB, and now the process runs for around
> 45 minutes before rolling back, and ends with the same error that we got at
> first - can't increase space in MeterGroup2.
> To verify that my understanding of the process of splitting partitions is
> correct, I created a new scheme, a new function, and a new copy of the table
> in question - identical to existing scheme/function/table in structure.
> I then put in the first and last 1000 rows for each range (e.g. top 1000 *
> order by FID asc where FID < 8000, then top 1000 * order by FID desc where
> FID < 8000, followed by top 1000 * order by FID asc where FID >= 8000 and top
> 1000 * order by FID desc where FID >= 8000.
> As expected, this indicates 2000 rows in each of the two partitions.
> Splitting the new partition, and checking the rows shows (as expected) 2000
> rows in the first two partitions, and none in the third.
> select index_id, partition_number, rows
> from sys.partitions
> where object_id = object_id('tbReadIntDevDtl')
> index_id partition_number rows
> -- -- --
> 1 1 2000
> 1 2 2000
> 1 3 0
> What could be causing this issue. Have I got something fundamentally wrong
> in my understanding of how RANGE SPLIT works?
> Thanks
> Bernard
> P.S. Please, no answers suggesting I should switch partitions, because that
> isn't what I'm trying to do. We will switch older partitions out, but here
> we simply want to direct new records into a new partition.
|||Beranrd
Check out this great article
http://www.simple-talk.com/sql/sql-server-2005/partitioned-tables-in-sql-server-2005/
"Bernard Sheppard" <BernardSheppard@.discussions.microsoft.com> wrote in
message news:C9A212E7-1A8D-4054-81C5-4E2DA6214025@.microsoft.com...
> Long Post (so you know what I've already tried).
> I'll start off with the definitions of existing objects, but in summary,
> I'm
> attempting to add a new range to a partition function, and expect this to
> be
> an almost instantaneous operation, but it is not (and, at the moment, I
> can't
> get it to complete at all).
> The partition scheme started off with two groups:
> CREATE PARTITION SCHEME [schemePartitonFile] AS PARTITION
> [fnPartitionFile]
> TO ([MeterGroup1], [MeterGroup2])
> We have managed to fill the second group (MeterGroup2) (poor planning),
> and
> so need to add a new partition.
> MeterGroup2 was specified not to grow past (the size of the LUN it was
> on -
> 0.5GB).
> The partition function we are using is based on a FileID (FID), and is
> currently defined as:
> CREATE PARTITION FUNCTION [fnPartitionFile](int) AS RANGE LEFT FOR VALUES
> (8000)
> So, all files < 8000 go into MeterGroup1, and all Files >= 8000 go into
> meter group 2.
> There are four tables using the scheme - for example:
> CREATE TABLE [dbo].[tbReadIntDevDtl](
> [FID] [int] NOT NULL,
> [Block] [smallint] NOT NULL,
> [Period] [tinyint] NOT NULL,
> [IntervalValue] [int] NOT NULL,
> [Quality] [char](1) NOT NULL,
> CONSTRAINT [PK_tbReadIntDevDtl] PRIMARY KEY CLUSTERED
> (
> [FID] ASC,
> [Block] ASC,
> [Period] ASC
> )ON [schemePartitonFile]([FID])
> )
> So with MeterGroup2 filled, we would like to add a new group to the
> partition scheme, and direct all new files to that group.
> Checked the current max FID: 31976
> What we expect to be able to do is:
> ALTER PARTITION SCHEME schemePartitonFile NEXT USED MeterGroup3
> ...followed by...
> ALTER PARTITION FUNCTION fnPartitionFile() SPLIT RANGE (31977)
> Given that the current max FID is 31976, we would expect to be able to run
> the alter partition function statement, and it would not need to do any
> physical movement of data, and should complete pretty much instantly,
> resulting in the following scheme...
> FID < 8000 in Partition 1
> FID >= 8000 AND FID < 31977 in Partition 2
> FID >= 31977 in Partition 3
> At first, I immediately got the following error:
> Could not allocate space for object
> 'dbo.tbReadIntDevDtl'.'PK_tbReadIntDevDtl' in database 'SageEMS' because
> the
> 'MeterGroup2' filegroup is full. Create disk space by deleting unneeded
> files, dropping objects in the filegroup, adding additional files to the
> filegroup, or setting autogrowth on for existing files in the filegroup.
> I increased the size of MeterGroup2 to use the 0.5GB of free space on the
> LUN, and then the process would run for around 45 minutes, then start
> rolling
> back, ending with an error that the database was out of log.
> I increased the log from 15GB to 36GB, and now the process runs for around
> 45 minutes before rolling back, and ends with the same error that we got
> at
> first - can't increase space in MeterGroup2.
> To verify that my understanding of the process of splitting partitions is
> correct, I created a new scheme, a new function, and a new copy of the
> table
> in question - identical to existing scheme/function/table in structure.
> I then put in the first and last 1000 rows for each range (e.g. top 1000 *
> order by FID asc where FID < 8000, then top 1000 * order by FID desc where
> FID < 8000, followed by top 1000 * order by FID asc where FID >= 8000 and
> top
> 1000 * order by FID desc where FID >= 8000.
> As expected, this indicates 2000 rows in each of the two partitions.
> Splitting the new partition, and checking the rows shows (as expected)
> 2000
> rows in the first two partitions, and none in the third.
> select index_id, partition_number, rows
> from sys.partitions
> where object_id = object_id('tbReadIntDevDtl')
> index_id partition_number rows
> -- -- --
> 1 1 2000
> 1 2 2000
> 1 3 0
> What could be causing this issue. Have I got something fundamentally
> wrong
> in my understanding of how RANGE SPLIT works?
> Thanks
> Bernard
> P.S. Please, no answers suggesting I should switch partitions, because
> that
> isn't what I'm trying to do. We will switch older partitions out, but
> here
> we simply want to direct new records into a new partition.
|||Thanks for the reply, Tibor.
That leads to a couple of follow up questions:
With RANGE LEFT, it would appear that the edge partition can't ever have
data (if I want to be able to quickly change ranges), which means that I
can't have a strategy where I fill an edge partition until full, and then
create a new partition and adjust the ranges so new data flows into it.
This is the strategy that I would like to use: we want to be able to load
data into "bucket" (last partition) where we always fill the last bucket
until (nearly) full, then start filling the next bucket. Each bucket is
sized to hold a reasonable amount of data (around 1 billion rows, or
thereabouts), but we can't accurately predict when we will fill a bucket.
We will eventually switch out then delete old data (once it is 7 years after
it was loaded) - but our date partitioning is less to do with the date that
the data is for, and more to do with the date it was loaded.
Any suggestions?
Thanks
"Tibor Karaszi" wrote:
> No, what you need to do is to always have an empty partition "at the end". And when you want to
> split, you split so you have two empty partitions. I.e., there will be no data movement when you
> split one empty partition into two empty partitions. Same basic principle goes for when you purge
> data (if you are going to do that). In other words, never populate your "unbound"/"edge" partitions.
>
|||I'm not sure I follow you, Bernard...
> With RANGE LEFT, it would appear that the edge partition can't ever have
> data (if I want to be able to quickly change ranges), which means that I
> can't have a strategy where I fill an edge partition until full
This is what I have problems with. How can you say "until full" for something which is unrestricted?
I assume that the values you add (what you are partitioning over) are either increasing or
decreasing. Otherwise, you wouldn't know that they go to the "last" or "first" partition. I also
assume that they are restricted in some sense, else you wouldn't be able to do a SPLIT later on.
Based on above, it seems that the values might as well go into a predefined unrestricted partition.
But perhaps it is just me being dense (wouldn't be the first time ;-) ).
To the best of my knowledge, the partition that you SPLIT or partitions that you MERGE need to be
empty to ensure meta-data only operations.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Bernard Sheppard" <BernardSheppard@.discussions.microsoft.com> wrote in message
news:DF45FCAC-2A4B-4481-927C-A17485CEC65C@.microsoft.com...
> Thanks for the reply, Tibor.
> That leads to a couple of follow up questions:
> With RANGE LEFT, it would appear that the edge partition can't ever have
> data (if I want to be able to quickly change ranges), which means that I
> can't have a strategy where I fill an edge partition until full, and then
> create a new partition and adjust the ranges so new data flows into it.
> This is the strategy that I would like to use: we want to be able to load
> data into "bucket" (last partition) where we always fill the last bucket
> until (nearly) full, then start filling the next bucket. Each bucket is
> sized to hold a reasonable amount of data (around 1 billion rows, or
> thereabouts), but we can't accurately predict when we will fill a bucket.
> We will eventually switch out then delete old data (once it is 7 years after
> it was loaded) - but our date partitioning is less to do with the date that
> the data is for, and more to do with the date it was loaded.
> Any suggestions?
> Thanks
>
> "Tibor Karaszi" wrote:
>
>
|||> With RANGE LEFT, it would appear that the edge partition can't ever have
> data (if I want to be able to quickly change ranges), which means that I
> can't have a strategy where I fill an edge partition until full, and then
> create a new partition and adjust the ranges so new data flows into it.
Regardless of the RANGE specification, you have the same issue. Like Tibor
mentioned, if you want to split a partition without data movement, plan so
that the last partition is always empty.
> This is the strategy that I would like to use: we want to be able to load
> data into "bucket" (last partition) where we always fill the last bucket
> until (nearly) full, then start filling the next bucket. Each bucket is
> sized to hold a reasonable amount of data (around 1 billion rows, or
> thereabouts), but we can't accurately predict when we will fill a bucket.
For a sliding window, I suggest you create your partition function to allow
for 2 empty (n and n - 1) partitions. Once you start filling the second
from last one (n - 1), split the last partition (n, which is still empty) to
prepare for the next time around. When you are ready to delete/archive the
oldest partition, simply switch out the first partition and merge it with
the second.
Hope this helps.
Dan Guzman
SQL Server MVP
"Bernard Sheppard" <BernardSheppard@.discussions.microsoft.com> wrote in
message news:DF45FCAC-2A4B-4481-927C-A17485CEC65C@.microsoft.com...
> Thanks for the reply, Tibor.
> That leads to a couple of follow up questions:
> With RANGE LEFT, it would appear that the edge partition can't ever have
> data (if I want to be able to quickly change ranges), which means that I
> can't have a strategy where I fill an edge partition until full, and then
> create a new partition and adjust the ranges so new data flows into it.
> This is the strategy that I would like to use: we want to be able to load
> data into "bucket" (last partition) where we always fill the last bucket
> until (nearly) full, then start filling the next bucket. Each bucket is
> sized to hold a reasonable amount of data (around 1 billion rows, or
> thereabouts), but we can't accurately predict when we will fill a bucket.
> We will eventually switch out then delete old data (once it is 7 years
> after
> it was loaded) - but our date partitioning is less to do with the date
> that
> the data is for, and more to do with the date it was loaded.
> Any suggestions?
> Thanks
>
> "Tibor Karaszi" wrote:
>
>
|||Hi Tibor, thanks, you've answered my question (with your very last statement).
Cheers.
"Tibor Karaszi" wrote:
> I'm not sure I follow you, Bernard...
>
> This is what I have problems with. How can you say "until full" for something which is unrestricted?
>
Physically full - each partition will (almost) fill a mounted disk (a SAN
LUN). Whilst I could distribute a filegroup across multiple LUNs, it makes
for more difficult management, and makes life more difficult for piecemeal
restores. If I can stick with a single filegroup per LUN, then my
file/filegroup/partitioning strategy can be automated.
I'm partitioning for a few reasons - recoverability, ability to archive
(read delete, or alternatively move to slow storage (e.g. read only on NTFS
compression), ability to restore subsets of data (e.g. just data loaded in
the last x month) into other environments, etc, ability to utilise multiple
LUNs on a SAN for maximum parallelism, etc.
My main table will grow to several terabytes and hundreds of billions of
rows. Distributing this (evenly) over many small LUNs will allow maintenance
activities such as backup, restore, integrity checks, etc to run at maximum
speed.
I used to use DPVs on SQL Server 2000.
> I assume that the values you add (what you are partitioning over) are either increasing or
> decreasing. Otherwise, you wouldn't know that they go to the "last" or "first" partition. I also
> assume that they are restricted in some sense, else you wouldn't be able to do a SPLIT later on.
>
Absolutely correct. My raw value that I am partitioning over is an identity
column that relates the data back to the batch in which it was recieved -
this ID is then used as part of the PK (and partition scheme input) for the
lower level data.
This means that I am only ever inserting into the last partition (and, for
that matter, physically in order due to the clustered index).
> Based on above, it seems that the values might as well go into a predefined unrestricted partition.
> But perhaps it is just me being dense (wouldn't be the first time ;-) ).
Yes, except I then can't partition across (fixed) size LUNSs.
> To the best of my knowledge, the partition that you SPLIT or partitions
that you MERGE need to be
> empty to ensure meta-data only operations.
That has hit the nail on the head, and tests I've done have confirmed this.
I've read (and re-read) BOL, and whilst it does describe where the new range
value goes (e.g. on LEFT, becomes part of the new partition), and it
indicates that if you split an existing range, data that falls into the new
range gets moved, it doesn't seem to state (at least clearly enough for me to
tell) that, even if there is no data at the split point, if there is any data
in the partition being split, it is not a meta-data only operation.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
Failure adding a new partition range to a partition function.
I'll start off with the definitions of existing objects, but in summary, I'm
attempting to add a new range to a partition function, and expect this to be
an almost instantaneous operation, but it is not (and, at the moment, I can'
t
get it to complete at all).
The partition scheme started off with two groups:
CREATE PARTITION SCHEME [schemePartitonFile] AS PARTITION [fnPartiti
onFile]
TO ([MeterGroup1], [MeterGroup2])
We have managed to fill the second group (MeterGroup2) (poor planning), and
so need to add a new partition.
MeterGroup2 was specified not to grow past (the size of the LUN it was on -
0.5GB).
The partition function we are using is based on a FileID (FID), and is
currently defined as:
CREATE PARTITION FUNCTION [fnPartitionFile](int) AS RANGE LEFT FOR VALUE
S
(8000)
So, all files < 8000 go into MeterGroup1, and all Files >= 8000 go into
meter group 2.
There are four tables using the scheme - for example:
CREATE TABLE [dbo].[tbReadIntDevDtl](
[FID] [int] NOT NULL,
[Block] [smallint] NOT NULL,
[Period] [tinyint] NOT NULL,
[IntervalValue] [int] NOT NULL,
[Quality] [char](1) NOT NULL,
CONSTRAINT [PK_tbReadIntDevDtl] PRIMARY KEY CLUSTERED
(
[FID] ASC,
[Block] ASC,
[Period] ASC
)ON [schemePartitonFile]([FID])
)
So with MeterGroup2 filled, we would like to add a new group to the
partition scheme, and direct all new files to that group.
Checked the current max FID: 31976
What we expect to be able to do is:
ALTER PARTITION SCHEME schemePartitonFile NEXT USED MeterGroup3
...followed by...
ALTER PARTITION FUNCTION fnPartitionFile() SPLIT RANGE (31977)
Given that the current max FID is 31976, we would expect to be able to run
the alter partition function statement, and it would not need to do any
physical movement of data, and should complete pretty much instantly,
resulting in the following scheme...
FID < 8000 in Partition 1
FID >= 8000 AND FID < 31977 in Partition 2
FID >= 31977 in Partition 3
At first, I immediately got the following error:
Could not allocate space for object
'dbo.tbReadIntDevDtl'.'PK_tbReadIntDevDtl' in database 'SageEMS' because the
'MeterGroup2' filegroup is full. Create disk space by deleting unneeded
files, dropping objects in the filegroup, adding additional files to the
filegroup, or setting autogrowth on for existing files in the filegroup.
I increased the size of MeterGroup2 to use the 0.5GB of free space on the
LUN, and then the process would run for around 45 minutes, then start rollin
g
back, ending with an error that the database was out of log.
I increased the log from 15GB to 36GB, and now the process runs for around
45 minutes before rolling back, and ends with the same error that we got at
first - can't increase space in MeterGroup2.
To verify that my understanding of the process of splitting partitions is
correct, I created a new scheme, a new function, and a new copy of the table
in question - identical to existing scheme/function/table in structure.
I then put in the first and last 1000 rows for each range (e.g. top 1000 *
order by FID asc where FID < 8000, then top 1000 * order by FID desc where
FID < 8000, followed by top 1000 * order by FID asc where FID >= 8000 and to
p
1000 * order by FID desc where FID >= 8000.
As expected, this indicates 2000 rows in each of the two partitions.
Splitting the new partition, and checking the rows shows (as expected) 2000
rows in the first two partitions, and none in the third.
select index_id, partition_number, rows
from sys.partitions
where object_id = object_id('tbReadIntDevDtl')
index_id partition_number rows
-- -- --
1 1 2000
1 2 2000
1 3 0
What could be causing this issue. Have I got something fundamentally wrong
in my understanding of how RANGE SPLIT works?
Thanks
Bernard
P.S. Please, no answers suggesting I should switch partitions, because that
isn't what I'm trying to do. We will switch older partitions out, but here
we simply want to direct new records into a new partition.> Given that the current max FID is 31976, we would expect to be able to run
> the alter partition function statement, and it would not need to do any
> physical movement of data, and should complete pretty much instantly,
> resulting in the following scheme...
No, what you need to do is to always have an empty partition "at the end". A
nd when you want to
split, you split so you have two empty partitions. I.e., there will be no da
ta movement when you
split one empty partition into two empty partitions. Same basic principle go
es for when you purge
data (if you are going to do that). In other words, never populate your "unb
ound"/"edge" partitions.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Bernard Sheppard" <BernardSheppard@.discussions.microsoft.com> wrote in mess
age
news:C9A212E7-1A8D-4054-81C5-4E2DA6214025@.microsoft.com...
> Long Post (so you know what I've already tried).
> I'll start off with the definitions of existing objects, but in summary, I
'm
> attempting to add a new range to a partition function, and expect this to
be
> an almost instantaneous operation, but it is not (and, at the moment, I ca
n't
> get it to complete at all).
> The partition scheme started off with two groups:
> CREATE PARTITION SCHEME [schemePartitonFile] AS PARTITION [fnParti
tionFile]
> TO ([MeterGroup1], [MeterGroup2])
> We have managed to fill the second group (MeterGroup2) (poor planning), an
d
> so need to add a new partition.
> MeterGroup2 was specified not to grow past (the size of the LUN it was on
-
> 0.5GB).
> The partition function we are using is based on a FileID (FID), and is
> currently defined as:
> CREATE PARTITION FUNCTION [fnPartitionFile](int) AS RANGE LEFT FOR VAL
UES
> (8000)
> So, all files < 8000 go into MeterGroup1, and all Files >= 8000 go into
> meter group 2.
> There are four tables using the scheme - for example:
> CREATE TABLE [dbo].[tbReadIntDevDtl](
> [FID] [int] NOT NULL,
> [Block] [smallint] NOT NULL,
> [Period] [tinyint] NOT NULL,
> [IntervalValue] [int] NOT NULL,
> [Quality] [char](1) NOT NULL,
> CONSTRAINT [PK_tbReadIntDevDtl] PRIMARY KEY CLUSTERED
> (
> [FID] ASC,
> [Block] ASC,
> [Period] ASC
> )ON [schemePartitonFile]([FID])
> )
> So with MeterGroup2 filled, we would like to add a new group to the
> partition scheme, and direct all new files to that group.
> Checked the current max FID: 31976
> What we expect to be able to do is:
> ALTER PARTITION SCHEME schemePartitonFile NEXT USED MeterGroup3
> ...followed by...
> ALTER PARTITION FUNCTION fnPartitionFile() SPLIT RANGE (31977)
> Given that the current max FID is 31976, we would expect to be able to run
> the alter partition function statement, and it would not need to do any
> physical movement of data, and should complete pretty much instantly,
> resulting in the following scheme...
> FID < 8000 in Partition 1
> FID >= 8000 AND FID < 31977 in Partition 2
> FID >= 31977 in Partition 3
> At first, I immediately got the following error:
> Could not allocate space for object
> 'dbo.tbReadIntDevDtl'.'PK_tbReadIntDevDtl' in database 'SageEMS' because t
he
> 'MeterGroup2' filegroup is full. Create disk space by deleting unneeded
> files, dropping objects in the filegroup, adding additional files to the
> filegroup, or setting autogrowth on for existing files in the filegroup.
> I increased the size of MeterGroup2 to use the 0.5GB of free space on the
> LUN, and then the process would run for around 45 minutes, then start roll
ing
> back, ending with an error that the database was out of log.
> I increased the log from 15GB to 36GB, and now the process runs for around
> 45 minutes before rolling back, and ends with the same error that we got a
t
> first - can't increase space in MeterGroup2.
> To verify that my understanding of the process of splitting partitions is
> correct, I created a new scheme, a new function, and a new copy of the tab
le
> in question - identical to existing scheme/function/table in structure.
> I then put in the first and last 1000 rows for each range (e.g. top 1000 *
> order by FID asc where FID < 8000, then top 1000 * order by FID desc where
> FID < 8000, followed by top 1000 * order by FID asc where FID >= 8000 and
top
> 1000 * order by FID desc where FID >= 8000.
> As expected, this indicates 2000 rows in each of the two partitions.
> Splitting the new partition, and checking the rows shows (as expected) 200
0
> rows in the first two partitions, and none in the third.
> select index_id, partition_number, rows
> from sys.partitions
> where object_id = object_id('tbReadIntDevDtl')
> index_id partition_number rows
> -- -- --
> 1 1 2000
> 1 2 2000
> 1 3 0
> What could be causing this issue. Have I got something fundamentally wron
g
> in my understanding of how RANGE SPLIT works?
> Thanks
> Bernard
> P.S. Please, no answers suggesting I should switch partitions, because th
at
> isn't what I'm trying to do. We will switch older partitions out, but her
e
> we simply want to direct new records into a new partition.|||Beranrd
Check out this great article
http://www.simple-talk.com/sql/sql-...r-20
05/
"Bernard Sheppard" <BernardSheppard@.discussions.microsoft.com> wrote in
message news:C9A212E7-1A8D-4054-81C5-4E2DA6214025@.microsoft.com...
> Long Post (so you know what I've already tried).
> I'll start off with the definitions of existing objects, but in summary,
> I'm
> attempting to add a new range to a partition function, and expect this to
> be
> an almost instantaneous operation, but it is not (and, at the moment, I
> can't
> get it to complete at all).
> The partition scheme started off with two groups:
> CREATE PARTITION SCHEME [schemePartitonFile] AS PARTITION
> [fnPartitionFile]
> TO ([MeterGroup1], [MeterGroup2])
> We have managed to fill the second group (MeterGroup2) (poor planning),
> and
> so need to add a new partition.
> MeterGroup2 was specified not to grow past (the size of the LUN it was
> on -
> 0.5GB).
> The partition function we are using is based on a FileID (FID), and is
> currently defined as:
> CREATE PARTITION FUNCTION [fnPartitionFile](int) AS RANGE LEFT FOR VAL
UES
> (8000)
> So, all files < 8000 go into MeterGroup1, and all Files >= 8000 go into
> meter group 2.
> There are four tables using the scheme - for example:
> CREATE TABLE [dbo].[tbReadIntDevDtl](
> [FID] [int] NOT NULL,
> [Block] [smallint] NOT NULL,
> [Period] [tinyint] NOT NULL,
> [IntervalValue] [int] NOT NULL,
> [Quality] [char](1) NOT NULL,
> CONSTRAINT [PK_tbReadIntDevDtl] PRIMARY KEY CLUSTERED
> (
> [FID] ASC,
> [Block] ASC,
> [Period] ASC
> )ON [schemePartitonFile]([FID])
> )
> So with MeterGroup2 filled, we would like to add a new group to the
> partition scheme, and direct all new files to that group.
> Checked the current max FID: 31976
> What we expect to be able to do is:
> ALTER PARTITION SCHEME schemePartitonFile NEXT USED MeterGroup3
> ...followed by...
> ALTER PARTITION FUNCTION fnPartitionFile() SPLIT RANGE (31977)
> Given that the current max FID is 31976, we would expect to be able to run
> the alter partition function statement, and it would not need to do any
> physical movement of data, and should complete pretty much instantly,
> resulting in the following scheme...
> FID < 8000 in Partition 1
> FID >= 8000 AND FID < 31977 in Partition 2
> FID >= 31977 in Partition 3
> At first, I immediately got the following error:
> Could not allocate space for object
> 'dbo.tbReadIntDevDtl'.'PK_tbReadIntDevDtl' in database 'SageEMS' because
> the
> 'MeterGroup2' filegroup is full. Create disk space by deleting unneeded
> files, dropping objects in the filegroup, adding additional files to the
> filegroup, or setting autogrowth on for existing files in the filegroup.
> I increased the size of MeterGroup2 to use the 0.5GB of free space on the
> LUN, and then the process would run for around 45 minutes, then start
> rolling
> back, ending with an error that the database was out of log.
> I increased the log from 15GB to 36GB, and now the process runs for around
> 45 minutes before rolling back, and ends with the same error that we got
> at
> first - can't increase space in MeterGroup2.
> To verify that my understanding of the process of splitting partitions is
> correct, I created a new scheme, a new function, and a new copy of the
> table
> in question - identical to existing scheme/function/table in structure.
> I then put in the first and last 1000 rows for each range (e.g. top 1000 *
> order by FID asc where FID < 8000, then top 1000 * order by FID desc where
> FID < 8000, followed by top 1000 * order by FID asc where FID >= 8000 and
> top
> 1000 * order by FID desc where FID >= 8000.
> As expected, this indicates 2000 rows in each of the two partitions.
> Splitting the new partition, and checking the rows shows (as expected)
> 2000
> rows in the first two partitions, and none in the third.
> select index_id, partition_number, rows
> from sys.partitions
> where object_id = object_id('tbReadIntDevDtl')
> index_id partition_number rows
> -- -- --
> 1 1 2000
> 1 2 2000
> 1 3 0
> What could be causing this issue. Have I got something fundamentally
> wrong
> in my understanding of how RANGE SPLIT works?
> Thanks
> Bernard
> P.S. Please, no answers suggesting I should switch partitions, because
> that
> isn't what I'm trying to do. We will switch older partitions out, but
> here
> we simply want to direct new records into a new partition.|||Thanks for the reply, Tibor.
That leads to a couple of follow up questions:
With RANGE LEFT, it would appear that the edge partition can't ever have
data (if I want to be able to quickly change ranges), which means that I
can't have a strategy where I fill an edge partition until full, and then
create a new partition and adjust the ranges so new data flows into it.
This is the strategy that I would like to use: we want to be able to load
data into "bucket" (last partition) where we always fill the last bucket
until (nearly) full, then start filling the next bucket. Each bucket is
sized to hold a reasonable amount of data (around 1 billion rows, or
thereabouts), but we can't accurately predict when we will fill a bucket.
We will eventually switch out then delete old data (once it is 7 years after
it was loaded) - but our date partitioning is less to do with the date that
the data is for, and more to do with the date it was loaded.
Any suggestions?
Thanks
"Tibor Karaszi" wrote:
> No, what you need to do is to always have an empty partition "at the end".
And when you want to
> split, you split so you have two empty partitions. I.e., there will be no
data movement when you
> split one empty partition into two empty partitions. Same basic principle
goes for when you purge
> data (if you are going to do that). In other words, never populate your "u
nbound"/"edge" partitions.
>|||I'm not sure I follow you, Bernard...
> With RANGE LEFT, it would appear that the edge partition can't ever have
> data (if I want to be able to quickly change ranges), which means that I
> can't have a strategy where I fill an edge partition until full
This is what I have problems with. How can you say "until full" for somethin
g which is unrestricted?
I assume that the values you add (what you are partitioning over) are either
increasing or
decreasing. Otherwise, you wouldn't know that they go to the "last" or "firs
t" partition. I also
assume that they are restricted in some sense, else you wouldn't be able to
do a SPLIT later on.
Based on above, it seems that the values might as well go into a predefined
unrestricted partition.
But perhaps it is just me being dense (wouldn't be the first time ;-) ).
To the best of my knowledge, the partition that you SPLIT or partitions that
you MERGE need to be
empty to ensure meta-data only operations.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Bernard Sheppard" <BernardSheppard@.discussions.microsoft.com> wrote in mess
age
news:DF45FCAC-2A4B-4481-927C-A17485CEC65C@.microsoft.com...
> Thanks for the reply, Tibor.
> That leads to a couple of follow up questions:
> With RANGE LEFT, it would appear that the edge partition can't ever have
> data (if I want to be able to quickly change ranges), which means that I
> can't have a strategy where I fill an edge partition until full, and then
> create a new partition and adjust the ranges so new data flows into it.
> This is the strategy that I would like to use: we want to be able to load
> data into "bucket" (last partition) where we always fill the last bucket
> until (nearly) full, then start filling the next bucket. Each bucket is
> sized to hold a reasonable amount of data (around 1 billion rows, or
> thereabouts), but we can't accurately predict when we will fill a bucket.
> We will eventually switch out then delete old data (once it is 7 years aft
er
> it was loaded) - but our date partitioning is less to do with the date tha
t
> the data is for, and more to do with the date it was loaded.
> Any suggestions?
> Thanks
>
> "Tibor Karaszi" wrote:
>
>|||> With RANGE LEFT, it would appear that the edge partition can't ever have
> data (if I want to be able to quickly change ranges), which means that I
> can't have a strategy where I fill an edge partition until full, and then
> create a new partition and adjust the ranges so new data flows into it.
Regardless of the RANGE specification, you have the same issue. Like Tibor
mentioned, if you want to split a partition without data movement, plan so
that the last partition is always empty.
> This is the strategy that I would like to use: we want to be able to load
> data into "bucket" (last partition) where we always fill the last bucket
> until (nearly) full, then start filling the next bucket. Each bucket is
> sized to hold a reasonable amount of data (around 1 billion rows, or
> thereabouts), but we can't accurately predict when we will fill a bucket.
For a sliding window, I suggest you create your partition function to allow
for 2 empty (n and n - 1) partitions. Once you start filling the second
from last one (n - 1), split the last partition (n, which is still empty) to
prepare for the next time around. When you are ready to delete/archive the
oldest partition, simply switch out the first partition and merge it with
the second.
Hope this helps.
Dan Guzman
SQL Server MVP
"Bernard Sheppard" <BernardSheppard@.discussions.microsoft.com> wrote in
message news:DF45FCAC-2A4B-4481-927C-A17485CEC65C@.microsoft.com...
> Thanks for the reply, Tibor.
> That leads to a couple of follow up questions:
> With RANGE LEFT, it would appear that the edge partition can't ever have
> data (if I want to be able to quickly change ranges), which means that I
> can't have a strategy where I fill an edge partition until full, and then
> create a new partition and adjust the ranges so new data flows into it.
> This is the strategy that I would like to use: we want to be able to load
> data into "bucket" (last partition) where we always fill the last bucket
> until (nearly) full, then start filling the next bucket. Each bucket is
> sized to hold a reasonable amount of data (around 1 billion rows, or
> thereabouts), but we can't accurately predict when we will fill a bucket.
> We will eventually switch out then delete old data (once it is 7 years
> after
> it was loaded) - but our date partitioning is less to do with the date
> that
> the data is for, and more to do with the date it was loaded.
> Any suggestions?
> Thanks
>
> "Tibor Karaszi" wrote:
>
>|||Hi Tibor, thanks, you've answered my question (with your very last statement
).
Cheers.
"Tibor Karaszi" wrote:
> I'm not sure I follow you, Bernard...
>
> This is what I have problems with. How can you say "until full" for someth
ing which is unrestricted?
>
Physically full - each partition will (almost) fill a mounted disk (a SAN
LUN). Whilst I could distribute a filegroup across multiple LUNs, it makes
for more difficult management, and makes life more difficult for piecemeal
restores. If I can stick with a single filegroup per LUN, then my
file/filegroup/partitioning strategy can be automated.
I'm partitioning for a few reasons - recoverability, ability to archive
(read delete, or alternatively move to slow storage (e.g. read only on NTFS
compression), ability to restore subsets of data (e.g. just data loaded in
the last x month) into other environments, etc, ability to utilise multiple
LUNs on a SAN for maximum parallelism, etc.
My main table will grow to several terabytes and hundreds of billions of
rows. Distributing this (evenly) over many small LUNs will allow maintenanc
e
activities such as backup, restore, integrity checks, etc to run at maximum
speed.
I used to use DPVs on SQL Server 2000.
> I assume that the values you add (what you are partitioning over) are eith
er increasing or
> decreasing. Otherwise, you wouldn't know that they go to the "last" or "fi
rst" partition. I also
> assume that they are restricted in some sense, else you wouldn't be able t
o do a SPLIT later on.
>
Absolutely correct. My raw value that I am partitioning over is an identity
column that relates the data back to the batch in which it was recieved -
this ID is then used as part of the PK (and partition scheme input) for the
lower level data.
This means that I am only ever inserting into the last partition (and, for
that matter, physically in order due to the clustered index).
> Based on above, it seems that the values might as well go into a predefine
d unrestricted partition.
> But perhaps it is just me being dense (wouldn't be the first time ;-) ).
Yes, except I then can't partition across (fixed) size LUNSs.
> To the best of my knowledge, the partition that you SPLIT or partitions
that you MERGE need to be
> empty to ensure meta-data only operations.
That has hit the nail on the head, and tests I've done have confirmed this.
I've read (and re-read) BOL, and whilst it does describe where the new range
value goes (e.g. on LEFT, becomes part of the new partition), and it
indicates that if you split an existing range, data that falls into the new
range gets moved, it doesn't seem to state (at least clearly enough for me t
o
tell) that, even if there is no data at the split point, if there is any dat
a
in the partition being split, it is not a meta-data only operation.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/