Partition switching on a nonaligned table?

hi folks,
i was wondering if it was possible to switch between partitions when utilized a non aligned table?
DECLARE @StartMonth DATE= '2014-01-01';
CREATE PARTITION FUNCTION MonthlyProductPF (DATETIME)
AS RANGE RIGHT FOR VALUES
(@StartMonth
, DATEADD(mm,1,@StartMonth)
, DATEADD(mm,2,@StartMonth)
, DATEADD(mm,3,@StartMonth)
, DATEADD(mm,4,@StartMonth)
, DATEADD(mm,5,@StartMonth)
, DATEADD(mm,6,@StartMonth)
, DATEADD(mm,7,@StartMonth)
, DATEADD(mm,8,@StartMonth)
, DATEADD(mm,9,@StartMonth)
, DATEADD(mm,10,@StartMonth)
, DATEADD(mm,11,@StartMonth)
CREATE PARTITION SCHEME MonthlyProductPS AS PARTITION MonthlyProductPF TO (
MonthlyProductFG1
,MonthlyProductFG2
,MonthlyProductFG3
,MonthlyProductFG4
,MonthlyProductFG5
,MonthlyProductFG6
,MonthlyProductFG7
,MonthlyProductFG8
,MonthlyProductFG9
,MonthlyProductFG10
,MonthlyProductFG11
,MonthlyProductFG12
,MonthlyProductFG13
,MonthlyProductFG14
I have a table with the following clustered index that sit on PRIMARY
ALTER TABLE [dbo].[Product] ADD CONSTRAINT [PK_Product] PRIMARY KEY CLUSTERED ([Id] ASC) ON [PRIMARY]
GO
and then I got a non clustered index sitting on the
CREATE NONCLUSTERED INDEX [IX_Product_OrderDate] ON [core].[OrderProduct]
[OrderDate] DESC
) ON [MonthlyProductPS](OrderDate)
GO
when I run:
alter table dbo.Product switch partition 5 to ph.ProductToPurge partition 14
I get an error:
Warning: The specified partition 5 for the table 'db.dbo.Product' was ignored in ALTER TABLE SWITCH statement because the table is not partitioned.
Msg 7733, Level 16, State 3, Line 1
'ALTER TABLE SWITCH' statement failed. The index 'IX_Product_OrderDate' is partitioned while table 'db.dbo.Product' is not partitioned.
I have also tried to disable the PK and got the error:
The ALTER TABLE SWITCH statement failed. The table "db.dbo.Product" has a disabled clustered index.
any suggestions on getting pass these error?
Thanks,

Partition switching is only possible when all indexes are placed on the partition scheme. Or at least a partition scheme using the same partitioning function.
The reason for this is simple to understand. Say that you have table that is partitioned on OrderDate. Then you have an index on CustomerID which is placed on PRIMARY. Now you want to make a partition switch to get rid of the orders from Dec 2013. But if
you were permitted to this in this situation, the index on CustomerID would still have pointers to the order from Dec 2013. This may sounds benign it isn't. This query:
   SELECT COUNT(*) FROM Orders
would return different results, depending on which index the optimizer decides to use.
In your case, it is the other way round, it is the index that is partitioned, but the table that is not. That is a little, well, unusual.
But if you want to be able to do paritition switching to age out old data fast, you need all indexes to be aligned, and the table you switch with needs to have the same set of indexes. Only when this is fulfilled, you do a metadata-only operation like a
partition switch.
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • Partition switching taking lots of time

    I have a partitioned table. All the partitions of this table are mapped to a single filegroup.
    When I am trying to switch partition, it is taking lots of time more than 5 mins for a single partition.
    I can see that there is a file in the filegroup and its size is very high that is 234GB.
    Can partition switching take more time due to file size?
    or is there any other issue?
    I need help in finding out what is the problem.
    Thanks,

    So you are running ALTER TABLE SWITCH? Check for blocking. The operation requires an Sch-M lock which means that it is blocked any query that is running, including queries using NOLOCK.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Partition Pruning - Dimension and FACT tables..

    Hi
    I have a DWH environment where we have partitioned the FACT table by a date column. This is RANGE partition. The TIME dimension table joins to the FACT table based on this date. However the end user queries will typically be fired using a different column in the time dimension that will hold more VIEWABLE date values (e.g.) in format MON-YYYY or YYYY-MM etc..
    The query is autogenerated by the viewer tool. The SQL has something like
    select sum(balance), MONTH from fact a, dim_time b
    where a.date = b.date and <-- this the partitioned key in fact
    b.month_year_col = 'Apr-2006' <-- Dimension filter.
    In the above case, Oracle is not doing PARTITION PRUNING. I have 24 period data and in the explain plan i can see it goes to the entire 24 periods. However if i change the query to
    select sum(balance), MONTH from fact a, dim_time b
    where a.date = b.date and <-- this the partitioned key in fact
    b.date = '31-Apr-2006' <-- Dimension filter.
    it does partition pruning. The explain plan shows that i goes to only one partition.
    Any help on this please. I would need the first query to use PARTITION PRUNING.
    Thanks
    bala

    Hi All
    Got it to work with these 3 parameters
    alter system set "_subquery_pruning_enabled" = true
    alter session set "_subquery_pruning_cost_factor"=1;
    alter session set "_subquery_pruning_reduction"=100;
    Thanks for all those who had a look into my question.
    Regards
    bala

  • Switch Linked (xl source) Tables - behavior change Excel 2010 PP vs. Excel 2013 PP -- In 2013 all calcs of table are lost

    Situation:
    PowerPivot 2010 Model based on 10 linked tables (this tables are generated and refreshed as needed by SQL 2012 MDS Excel-AddIn)
    Unfortunately Excel MDS AddIn changes sometimes the tablename (case: MDS Add-In Filter changed, MDS Server changed). So after Change of tablename we have to fix the powerpivot link to this Excel tables in powerpivot to get powerpivot refresh working again
    Problem:
    With Excel 2010 PowerPivot this was possible without big Problems. As Long as table has identical structure one can Change/Switch the table in powerpivot Windows > Ribbon "Linked" Table > DropDown "Linked Table X" or during update
    via Dialog "Errors in Linked Table"
    After upgrading the solution to Excel 2013 this is not possible any more without loosing any column- or measure calcs defined for this table! :( Every time you Change the assigned Excel table for an existing linked powerpivot table..you
    get following Dialog:
    "You are changing the source of X to Excel table Y. Changing the source will remove all formatting, measures, KPIs, hierarchies, and other Settings applied to the table. Are you sure you want to to continute?"
    Does anyone found a Workaround for persisting existing calc of linked tables when changing the sourcetable (to another Excel table with same structure)??
    Dear MS, this is IMHO really a step backwards and blocks the migration of our existing Excel 2010 PowerPivot Solution? Should i create a connect entry for that?!
    Version-Info:
    2010 Version: 11.0.3000.0 (PP Ribbon>Settings)
    2013 Version: 11.0.2809.81 (Product version displayed for dll c:\program files\Microsoft Office\Office15\Addins\PowerPivot excel Add-In\PowerPivotExcelClientAddIn.dll)

    There is a very similar issue discussed here where i tried to show the different behavior in terms of linked tables in Excel/PowerPivot 2010 vs 2013
    http://social.technet.microsoft.com/Forums/en-US/8fd927f7-30fd-49b7-809c-cb1414955638/linked-tables-excel-2013-vs-2010-difference?forum=sqlkjpowerpivotforexcel
    maybe it helps you to understand the issue
    I assume that MDS creates a new table every time you refresh it thereby breaking the link to PowerPivot
    in case you only have calculated measure you may created a separate, independent linked table and define all calculated measures there
    this way they at least would not get removed
    hth,
    gerhard
    Gerhard Brueckl
    blogging @ http://blog.gbrueckl.at
    working @ http://www.pmOne.com

  • Problem with a 2 columns Range Partitioning for a indexed organized table

    have an indexed organized table with a 2 column PK. the first field (datum) is a date field the second field (installatieid) is a number(2) field.
    Every minute a 7 records are inserted (installatieid 0-6).
    I like to partition this table with one partition per year per installatieid.
    I tried to do it with:
    partition by range(datum,installatieid)
    (partition P_2004_0 values less than (to_date('2004-01,'yyyy-mm'),1)
    ,partition P_2004_6 values less than (to_date('2004-01','yyyy-mm'),7)
    partition P_2005_0 values less than (to_date('2005-01','yyyy-mm'),1)
    ,partition P_2005_6 values less than (to_date('2005-01','yyyy-mm'),7)
    but now only the P_2004_0 and P_2005_0 are filled.
    I thought about to combine a range partition on datum with a list subpartition on installatieid, but I read this is not allowed with an index organized table.
    How can I solve this problem.

    partition by range(datum,installatieid)
    (partition P_2004_0 values less than
    (to_date('2004-01,'yyyy-mm'))
    ,partition P_2004_6 values less than
    (to_date('2004-07','yyyy-mm'))
    partition P_2005_0 values less than
    (to_date('2005-01','yyyy-mm'))
    ,partition P_2005_6 values less than
    (to_date('2005-07','yyyy-mm'))
    ? Sorry haven't got time to test it this morning ;0)

  • Partitioning for Fact and Bridge tables

    In our data warehouse we have a fact table having 35 million records which keeps monthly snapshot of data. This has been range partitioned on date key for each month end. We have another bridge table having around 50 million records, which is also partitioned the same way. These two tables can be joined on some fields, one of which is date key. When I run a query which uses both of these tables to display data for a month, it uses partitions in fact but does a full scan on bridge table. Partitions of bridge table are not being used at all. This results in very long response time.
    Can you suggest me some way to make it work?
    Thanks

    That's a matter of policy.Does your organisation execute a strict differentiation between ETL developers and DBAs? Then it's probably up to the DBAs to set up the tables, but of course you have to tell them the structures of the tables that they shall create for you.Other organisations allow their ETL developers to create tables "on the fly" in development environments. If this the case for you, then it's up to you. If this is not what you wanted to know, could you please post your question differently so that we can clearly understand what you mean? Regards,Nico

  • Kbd command to switch views (to light table)???

    Hello all,
    I love Keynote, but would like to know how I can switch view modes from the keyboard, or how I can put a direct "light table" button in the tool bar.
    Hasn't anyone thought of this?
    stp

    http://www.cisco.com/univercd/cc/td/doc/product/l3sw/4908g_l3/ios_12/10w518e/config/guidefmx.htm
    http://www.cisco.com/univercd/cc/td/doc/product/l3sw/4908g_l3/ios_12/10w518e/config/index.htm
    Above are the software cofigs guides for the 2948G-L3 with a 12.0(14)W5(20) IOS.
    I concur that the show bridge command will show you.
    Router# show bridge bridge-group-number |
    interface address
    Display classes of entries in the bridge forwarding database

  • Sort on  Shipment Number Switcher in PO details table in iProc doesn't work

    The Shipment numbers column of the PO Details table which are a part of
    Requisition details page of iProc appear in descending order. We want to sort this in an ascending order, but setting the Sort Allowed property of the field to Yes/Ascending does not give desired result.
    First of all, the column is displayed not by "PosShipmentNum" field (rendered False) but by a "ShipNumType" switcher. Setting this switcher's Sort Allowed property Yes/Ascending does not work either. Instead it adds the following code snippet is added to the VO query at runtime:
    QRSLT WHERE (PO_LINE_ID in (select po_line_id from PO_DISTRIBUTIONS_ALL pod , po_req_distributions_all pord, po_requisition_lines_all por where pord.DISTRIBUTION_ID = pod.REQ_DISTRIBUTION_ID and pord.requisition_line_id =
    por.requisition_line_id and por.requisition_header_id= :1 ) AND
    PO_RELEASE_ID is null AND PO_LINE_ID = :2) ORDER BY SHIP_TYPE asc
    and gives the following error:
    java.sql.SQLException: ORA-00904: "SHIP_TYPE": invalid identifier.
    It looks like some code is overwriting the properties set at the page level.
    Any pointers on how to sort a switcher field would be very helpful.
    Thanks.

    Is there any way to make it work on Oracle 9i?
    michaels>  select * from v$version
    BANNER                                                         
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    PL/SQL Release 9.2.0.8.0 - Production                          
    CORE     9.2.0.8.0     Production                                      
    TNS for HPUX: Version 9.2.0.8.0 - Production                   
    NLSRTL Version 9.2.0.8.0 - Production                          
    michaels>  create table persons (
        id  number(9)
           ,surname  varchar2(50)
              ,constraint persons_pk primary key (id)    )
    Table created.
    michaels>  create or replace type t_number_array as table of number;
    Type created.
    michaels>  create or replace procedure p_mrgts2 (p_id persons.id%type)
    is
       l_ids   t_number_array;
    begin
       l_ids := t_number_array (p_id);
       merge into persons p
          using (select * from table (cast (l_ids as t_number_array))) d
          on (p.id = d.column_value)
          when matched then
             update set surname = 'Updated'
          when not matched then
             insert (id, surname) values (d.column_value, 'Inserted');
    end p_mrgts2;
    Procedure created.
    michaels>  exec p_mrgts2(1)
    PL/SQL procedure successfully completed.
    michaels>  select * from persons
            ID SURNAME                                          
             1 Inserted                                         
    1 row selected.

  • Query to find the partitioned column(s) of a table.

    Guys,
    I've a partitioned table.I need to know the column(s) of the table which has been selected for partitioning.
    But none of the below tables below provide me the info:
    DBA_TABLES
    DBA_TAB_PARTITIONS
    DBA_TAB_SUBPARTITIONS
    Thoughts plz??
    Regards,
    Bhagat

    Guys,
    I've an index which is partitioned.
    From the resultset below,Would someone help me understand the range of values which each of the partition would hold?
    SQL> SELECT INDEX_NAME,PARTITION_NAME,HIGH_VALUE FROM DBA_IND_PARTITIONS WHERE INDEX_NAME='FACT_605';
    INDEX_NAME                     PARTITION_NAME                 HIGH_VALUE
    FACT_605                       P_A8_2114                      'A8', 2114, MAXVALUE
    FACT_605                       P_G8_2114                      'G8', '2114', MAXVALUE
    FACT_605                       Z_LAST_PARTITION               MAXVALUE, MAXVALUE, MAXVALUE
    Thanks,
    Bhagat                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Replicated Table - has_replication_filter bit does not reset

    Running SQL Server 2005 SP2. Transactional replication with no updating subscriber.  Push to subscriber.
    What I am trying to do is implement partition switching on a replicated table.  My process looks like:
    BEGIN TRAN
    EXEC sp_dropsubscription @publication = 'PUBLICATION_LogTest',
        @article = 'testlog', @subscriber = N'all', @destination_db = N'all'
    EXEC sp_droparticle @publication = 'PUBLICATION_LogTest',
        @article = 'testlog', @force_invalidate_snapshot = 1
    ALTER TABLE testlog switch PARTITION 2 TO Testlog_delete PARTITION 2
    EXEC sp_addarticle @publication = 'PUBLICATION_LogTest',
        @article =  'testlog', @source_owner = N'dbo', @source_object =  'testlog',
        @type = N'logbased', @pre_creation_cmd = N'none', @schema_option = 0,
        @destination_table =  'testlog', @destination_owner = N'dbo'
        @force_invalidate_snapshot = 1
    COMMIT
    EXEC sp_startpublication_snapshot @publication = 'PUBLICATION_LogTest'
    (testlog_delete is not replicated)
    When I try to alter the table, I get an error message:
    ALTER TABLE SWITCH statement failed because the table 'sand.dbo.testlog' is marked for replication.
    If I look in sys.tables after the DROP subscription/article, I see the the has_replication_filter bit = 1 (the is_published = 0, and is_replicated = 0).
    Note that none of the tables are filtered vertically or horizontally.
    If I start SQL Server in single user mode and use DAC, I can reset the has_replication_filtered bit = (0) with:
    EXEC sp_MSsetfilteredstatus <ObjectId>
    Then I can do the partition switch.
    ...but this stored proc is unavailable outside of DAC.
    So three questions:
    (1) Why causes the has_replication_filter bit to get set to 1 (it is happening on some of my tables, but not all of them)
    (2) How can reset this bit outside of DAC
    (3) Is there a better way (outside of upgrading to SQL Server 2008) to manage partition switching on a replicated table?

    I had the same problem and the way I solved it was to create a dummy publication with a filter for the table I needed to switch partitions on (the filter I used was one that would not have any data: "where TestTime < '19700101'"). I saved the publication
    without creating a snaphot. I checked "sys.tables" and saw the bits were set as you mentioned above. I then deleted the filter from the publication and saw that the "has_replication_filter"
    bit got set to "0". I then dropped that publication and the bits stayed at "0".
    I am now able to switch the partitions on that non-replicated table without having to use the DAC and try to update the system tables.

  • Switch in partition to a partitioned table where it has indexes on it

    CREATE TABLE [dbo].[Partitioned_Table](
    [Partition_Id] [int] NOT NULL,
    [FIL_CRT_DT] [datetime2](7) NOT NULL,
    GO
    SET ANSI_PADDING OFF
    GO
    CREATE NONCLUSTERED INDEX [idx2] ON [dbo].[Partitioned_Table]
    [FIL_CRT_DT] ASC
    )INCLUDE(Partition_Id) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    Partition_Function and scheme are on the column Partition_Id and on primary filegroup.
    Now I am trying to switch in a partition. But it is failing giving me this error:
    ALTER TABLE SWITCH statement failed. There is no identical index in source table 'New_Table' for the index 'idx2'in target table 'Partitioned_Table' .
    Is there a way to switch in a table with no indeses on it into the base table where we have indexes without dropping and creating them?

    Hello,
    For a partition switch the source and destination table must have identical indexes, there is no way around.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Sql server partition parent table and reference not partition child table

     
    Hi,
    I have two tables in SQL Server 2008 R2, Parent and Child Table.  
    Parent has date time, and it is partitioned monthly,  there is a Child table which just refer the Parent table using Foreign key relation.   
    is there any problem the non-partitioned child table referring to a partitioned parent table?
    Thanks,
    Areef

    The tables will need to be offline for the operation. "Offline" here, means that you wrap the entire operation in a transaction. Ideally, this transaction would:
    1) Drop the foreign key.
    2) Use ALTER TABLE SWITCH to drop the old data.
    3) Use ALTER PARTITION FUNCTION to drop the old empty partition.
    4) Use ALTER PARTITION FUNCTION to add a new empty partition.
    5) Reapply the foreign keys WITH CHECK.
    All but the last operation are metadata-only operation (provided that you do them right). To perform the last operation, SQL Server must scan the child tbale and verify that all keys are present in the parent table. This can take some time for larger tables.
    During the transaction, SQL Server holds Sch-M locks on the table, which means that are entirely inaccessible, even for queries running with NOLOCK.
    You avoid this the scan by applying the fkey constraint WITH NOCHECK, but this can have impact on query plans, as SQL Server will not consider the constraint as trusted.
    An alternative which should not be entirely dismissed is to use partitioned
    views instead. With partitioned views, the foreign keys are not an issue, because each partition is a pair of tables, with its own local fkey.
    As for the second question: it appears to be completely pointless to partition the parent, but not the child table. Or does the child table only have rows for a smaller set of the rows in the parent?
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Fact and dimension table partition

    My team is implementing new data-warehouse. I would like to know that when  should we plan to do partition of fact and dimension table, before data comes in or after?

    Hi,
    It is recommended to partition Fact table (Where we will have huge data). Automate the partition so that each day it will create a new partition to hold latest data (Split the previous partition into 2). Best practice is to create partition on transaction
    timestamps so load the incremental data into a empty table called (Table_IN) and then Switch that data into main table (Table). Make sure your tables (Table and Table_IN) should be on one file group.
    Refer below content for detailed info
    Designing and Administrating Partitions in SQL Server 2012
    A popular method of better managing large and active tables and indexes is the use of partitioning. Partitioning is a feature for segregating I/O workload within
    SQL Server database so that I/O can be better balanced against available I/O subsystems while providing better user response time, lower I/O latency, and faster backups and recovery. By partitioning tables and indexes across multiple filegroups, data retrieval
    and management is much quicker because only subsets of the data are used, meanwhile ensuring that the integrity of the database as a whole remains intact.
    Tip
    Partitioning is typically used for administrative or certain I/O performance scenarios. However, partitioning can also speed up some queries by enabling
    lock escalation to a single partition, rather than to an entire table. You must allow lock escalation to move up to the partition level by setting it with either the Lock Escalation option of Database Options page in SSMS or by using the LOCK_ESCALATION option
    of the ALTER TABLE statement.
    After a table or index is partitioned, data is stored horizontally across multiple filegroups, so groups of data are mapped to individual partitions. Typical
    scenarios for partitioning include large tables that become very difficult to manage, tables that are suffering performance degradation because of excessive I/O or blocking locks, table-centric maintenance processes that exceed the available time for maintenance,
    and moving historical data from the active portion of a table to a partition with less activity.
    Partitioning tables and indexes warrants a bit of planning before putting them into production. The usual approach to partitioning a table or index follows these
    steps:
    1. Create
    the filegroup(s) and file(s) used to hold the partitions defined by the partitioning scheme.
    2. Create
    a partition function to map the rows of the table or index to specific partitions based on the values in a specified column. A very common partitioning function is based on the creation date of the record.
    3. Create
    a partitioning scheme to map the partitions of the partitioned table to the specified filegroup(s) and, thereby, to specific locations on the Windows file system.
    4. Create
    the table or index (or ALTER an existing table or index) by specifying the partition scheme as the storage location for the partitioned object.
    Although Transact-SQL commands are available to perform every step described earlier, the Create Partition Wizard makes the entire process quick and easy through
    an intuitive point-and-click interface. The next section provides an overview of using the Create Partition Wizard in SQL Server 2012, and an example later in this section shows the Transact-SQL commands.
    Leveraging the Create Partition Wizard to Create Table and Index Partitions
    The Create Partition Wizard can be used to divide data in large tables across multiple filegroups to increase performance and can be invoked by right-clicking
    any table or index, selecting Storage, and then selecting Create Partition. The first step is to identify which columns to partition by reviewing all the columns available in the Available Partitioning Columns section located on the Select a Partitioning Column
    dialog box, as displayed in Figure 3.13. This screen also includes additional options such as the following:
    Figure 3.13. Selecting a partitioning column.
    The next screen is called Select a Partition Function. This page is used for specifying the partition function where the data will be partitioned. The options
    include using an existing partition or creating a new partition. The subsequent page is called New Partition Scheme. Here a DBA will conduct a mapping of the rows selected of tables being partitioned to a desired filegroup. Either a new partition scheme should
    be used or a new one needs to be created. The final screen is used for doing the actual mapping. On the Map Partitions page, specify the partitions to be used for each partition and then enter a range for the values of the partitions. The
    ranges and settings on the grid include the following:
    Note
    By opening the Set Boundary Values dialog box, a DBA can set boundary values based on dates (for example, partition everything in a column after a specific
    date). The data types are based on dates.
    Designing table and index partitions is a DBA task that typically requires a joint effort with the database development team. The DBA must have a strong understanding
    of the database, tables, and columns to make the correct choices for partitioning. For more information on partitioning, review Books Online.
    Enhancements to Partitioning in SQL Server 2012
    SQL Server 2012 now supports as many as 15,000 partitions. When using more than 1,000 partitions, Microsoft recommends that the instance of SQL Server have at
    least 16Gb of available memory. This recommendation particularly applies to partitioned indexes, especially those that are not aligned with the base table or with the clustered index of the table. Other Data Manipulation Language statements (DML) and Data
    Definition Language statements (DDL) may also run short of memory when processing on a large number of partitions.
    Certain DBCC commands may take longer to execute when processing a large number of partitions. On the other hand, a few DBCC commands can be scoped to the partition
    level and, if so, can be used to perform their function on a subset of data in the partitioned table.
    Queries may also benefit from a new query engine enhancement called partition elimination. SQL Server uses partition enhancement automatically if it is available.
    Here’s how it works. Assume a table has four partitions, with all the data for customers whose names begin with R, S, or T in the third partition. If a query’s WHERE clause
    filters on customer name looking for ‘System%’, the query engine knows that it needs only to partition three to answer
    the request. Thus, it might greatly reduce I/O for that query. On the other hand, some queries might take longer if there are more than 1,000 partitions and the query is not able to perform partition elimination.
    Finally, SQL Server 2012 introduces some changes and improvements to the algorithms used to calculate partitioned index statistics. Primarily, SQL Server 2012
    samples rows in a partitioned index when it is created or rebuilt, rather than scanning all available rows. This may sometimes result in somewhat different query behavior compared to the same queries running on SQL Server 2012.
    Administrating Data Using Partition Switching
    Partitioning is useful to access and manage a subset of data while losing none of the integrity of the entire data set. There is one limitation, though. When
    a partition is created on an existing table, new data is added to a specific partition or to the default partition if none is specified. That means the default partition might grow unwieldy if it is left unmanaged. (This concept is similar to how a clustered
    index needs to be rebuilt from time to time to reestablish its fill factor setting.)
    Switching partitions is a fast operation because no physical movement of data takes place. Instead, only the metadata pointers to the physical data are altered.
    You can alter partitions using SQL Server Management Studio or with the ALTER TABLE...SWITCH
    Transact-SQL statement. Both options enable you to ensure partitions are
    well maintained. For example, you can transfer subsets of data between partitions, move tables between partitions, or combine partitions together. Because the ALTER TABLE...SWITCH statement
    does not actually move the data, a few prerequisites must be in place:
    • Partitions must use the same column when switching between two partitions.
    • The source and target table must exist prior to the switch and must be on the same filegroup, along with their corresponding indexes,
    index partitions, and indexed view partitions.
    • The target partition must exist prior to the switch, and it must be empty, whether adding a table to an existing partitioned table
    or moving a partition from one table to another. The same holds true when moving a partitioned table to a nonpartitioned table structure.
    • The source and target tables must have the same columns in identical order with the same names, data types, and data type attributes
    (length, precision, scale, and nullability). Computed columns must have identical syntax, as well as primary key constraints. The tables must also have the same settings for ANSI_NULLS and QUOTED_IDENTIFIER properties.
    Clustered and nonclustered indexes must be identical. ROWGUID properties
    and XML schemas must match. Finally, settings for in-row data storage must also be the same.
    • The source and target tables must have matching nullability on the partitioning column. Although both NULL and NOT
    NULL are supported, NOT
    NULL is strongly recommended.
    Likewise, the ALTER TABLE...SWITCH statement
    will not work under certain circumstances:
    • Full-text indexes, XML indexes, and old-fashioned SQL Server rules are not allowed (though CHECK constraints
    are allowed).
    • Tables in a merge replication scheme are not allowed. Tables in a transactional replication scheme are allowed with special caveats.
    Triggers are allowed on tables but must not fire during the switch.
    • Indexes on the source and target table must reside on the same partition as the tables themselves.
    • Indexed views make partition switching difficult and have a lot of extra rules about how and when they can be switched. Refer to
    the SQL Server Books Online if you want to perform partition switching on tables containing indexed views.
    • Referential integrity can impact the use of partition switching. First, foreign keys on other tables cannot reference the source
    table. If the source table holds the primary key, it cannot have a primary or foreign key relationship with the target table. If the target table holds the foreign key, it cannot have a primary or foreign key relationship with the source table.
    In summary, simple tables can easily accommodate partition switching. The more complexity a source or target table exhibits, the more likely that careful planning
    and extra work will be required to even make partition switching possible, let alone efficient.
    Here’s an example where we create a partitioned table using a previously created partition scheme, called Date_Range_PartScheme1.
    We then create a new, nonpartitioned table identical to the partitioned table residing on the same filegroup. We finish up switching the data from the partitioned table into the nonpartitioned table:
    CREATE TABLE TransactionHistory_Partn1 (Xn_Hst_ID int, Xn_Type char(10)) ON Date_Range_PartScheme1 (Xn_Hst_ID) ; GO CREATE TABLE TransactionHistory_No_Partn (Xn_Hst_ID int, Xn_Type
    char(10)) ON main_filegroup ; GO ALTER TABLE TransactionHistory_Partn1 SWITCH partition1 TO TransactionHistory_No_Partn; GO
    The next section shows how to use a more sophisticated, but very popular, approach to partition switching called a sliding
    window partition.
    Example and Best Practices for Managing Sliding Window Partitions
    Assume that our AdventureWorks business is booming. The sales staff, and by extension the AdventureWorks2012 database, is very busy. We noticed over time that
    the TransactionHistory table is very active as sales transactions are first entered and are still very active over their first month in the database. But the older the transactions are, the less activity they see. Consequently, we’d like to automatically group
    transactions into four partitions per year, basically containing one quarter of the year’s data each, in a rolling partitioning. Any transaction older than one year will be purged or archived.
    The answer to a scenario like the preceding one is called a sliding window partition because
    we are constantly loading new data in and sliding old data over, eventually to be purged or archived. Before you begin, you must choose either a LEFT partition function window or a RIGHT partition function window:
    1. How
    data is handled varies according to the choice of LEFT or RIGHT partition function window:
    • With a LEFT strategy, partition1 holds the oldest data (Q4 data), partition2 holds data that is 6- to 9-months old (Q3), partition3
    holds data that is 3- to 6-months old (Q2), and partition4 holds recent data less than 3-months old.
    • With a RIGHT strategy, partition4 holds the holds data (Q4), partition3 holds Q3 data, partition2 holds Q2 data, and partition1
    holds recent data.
    • Following the best practice, make sure there are empty partitions on both the leading edge (partition0) and trailing edge (partition5)
    of the partition.
    • RIGHT range functions usually make more sense to most people because it is natural for most people to to start ranges at their lowest
    value and work upward from there.
    2. Assuming
    that a RIGHT partition function windows is used, we first use the SPLIT subclause of the ALTER PARTITION FUNCTIONstatement
    to split empty partition5 into two empty partitions, 5 and 6.
    3. We
    use the SWITCH subclause
    of ALTER TABLE to
    switch out partition4 to a staging table for archiving or simply to drop and purge the data. Partition4 is now empty.
    4. We
    can then use MERGE to
    combine the empty partitions 4 and 5, so that we’re back to the same number of partitions as when we started. This way, partition3 becomes the new partition4, partition2 becomes the new partition3, and partition1 becomes the new partition2.
    5. We
    can use SWITCH to
    push the new quarter’s data into the spot of partition1.
    Tip
    Use the $PARTITION system
    function to determine where a partition function places values within a range of partitions.
    Some best practices to consider for using a slide window partition include the following:
    • Load newest data into a heap, and then add indexes after the load is finished. Delete oldest data or, when working with very large
    data sets, drop the partition with the oldest data.
    • Keep an empty staging partition at the leftmost and rightmost ends of the partition range to ensure that the partitions split when
    loading in new data, and merge, after unloading old data, do not cause data movement.
    • Do not split or merge a partition already populated with data because this can cause severe locking and explosive log growth.
    • Create the load staging table in the same filegroup as the partition you are loading.
    • Create the unload staging table in the same filegroup as the partition you are deleting.
    • Don’t load a partition until its range boundary is met. For example, don’t create and load a partition meant to hold data that is
    one to two months older before the current data has aged one month. Instead, continue to allow the latest partition to accumulate data until the data is ready for a new, full partition.
    • Unload one partition at a time.
    • The ALTER TABLE...SWITCH statement
    issues a schema lock on the entire table. Keep this in mind if regular transactional activity is still going on while a table is being partitioned.
    Thanks Shiven:) If Answer is Helpful, Please Vote

  • Switch partitions and default values

    MSSQL 2012
    Can I switch partitions when the target has default value for a column, but the source doesnt? if so, will the default values be applied? 
    Thanks

    Hello,
    Do a simple test:
    CREATE TABLE dbo.Source (id int NOT NULL, updatestamp datetime NULL)
    CREATE TABLE dbo.Destination (id int NOT NULL, updatestamp datetime NULL DEFAULT(GETDATE()));
    GO
    INSERT INTO dbo.Source (id) VALUES (1);
    GO
    ALTER TABLE dbo.Source SWITCH PARTITION 1 TO dbo.Destination;
    SELECT *
    FROM dbo.Destination;
    Yes, it works.
    No, during a Partition Switch the data won't be modified.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Performance issues with version enable partitioned tables?

    Hi all,
    Are there any known performance issues with version enable partitioned tables?
    I’ve been doing some performance testes with a large version enable partitioned table and it seems that OCB optimiser is choosing very expensive plans during merge operations.
    Tanks in advance,
    Vitor
    Example:
         Object Name     Rows     Bytes     Cost     Object Node     In/Out     PStart     PStop
    UPDATE STATEMENT Optimizer Mode=CHOOSE          1          249                    
    UPDATE     SIG.SIG_QUA_IMG_LT                                   
    NESTED LOOPS SEMI          1     266     249                    
    PARTITION RANGE ALL                                   1     9
    TABLE ACCESS FULL     SIG.SIG_QUA_IMG_LT     1     259     2               1     9
    VIEW     SYS.VW_NSO_1     1     7     247                    
    NESTED LOOPS          1     739     247                    
    NESTED LOOPS          1     677     247                    
    NESTED LOOPS          1     412     246                    
    NESTED LOOPS          1     114     244                    
    INDEX RANGE SCAN     WMSYS.MODIFIED_TABLES_PK     1     62     2                    
    INDEX RANGE SCAN     SIG.QIM_PK     1     52     243                    
    TABLE ACCESS BY GLOBAL INDEX ROWID     SIG.SIG_QUA_IMG_LT     1     298     2               ROWID     ROW L
    INDEX RANGE SCAN     SIG.SIG_QUA_IMG_PKI$     1          1                    
    INDEX RANGE SCAN     WMSYS.WM$NEXTVER_TABLE_NV_INDX     1     265     1                    
    INDEX UNIQUE SCAN     WMSYS.MODIFIED_TABLES_PK     1     62                         
    /* Formatted on 2004/04/19 18:57 (Formatter Plus v4.8.0) */                                        
    UPDATE /*+ USE_NL(Z1) ROWID(Z1) */sig.sig_qua_img_lt z1                                        
    SET z1.nextver =                                        
    SYS.ltutil.subsversion                                        
    (z1.nextver,                                        
    SYS.ltutil.getcontainedverinrange (z1.nextver,                                        
    'SIG.SIG_QUA_IMG',                                        
    'NpCyPCX3dkOAHSuBMjGioQ==',                                        
    4574,                                        
    4575                                        
    4574                                        
    WHERE z1.ROWID IN (
    (SELECT /*+ ORDERED USE_NL(T1) USE_NL(T2) USE_NL(J2) USE_NL(J3)
    INDEX(T1 QIM_PK) INDEX(T2 SIG_QUA_IMG_PKI$)
    INDEX(J2 WM$NEXTVER_TABLE_NV_INDX) INDEX(J3 MODIFIED_TABLES_PK) */
    t2.ROWID
    FROM (SELECT /*+ INDEX(WM$MODIFIED_TABLES MODIFIED_TABLES_PK) */
    UNIQUE VERSION
    FROM wmsys.wm$modified_tables
    WHERE table_name = 'SIG.SIG_QUA_IMG'
    AND workspace = 'NpCyPCX3dkOAHSuBMjGioQ=='
    AND VERSION > 4574
    AND VERSION <= 4575) j1,
    sig.sig_qua_img_lt t1,
    sig.sig_qua_img_lt t2,
    wmsys.wm$nextver_table j2,
    (SELECT /*+ INDEX(WM$MODIFIED_TABLES MODIFIED_TABLES_PK) */
    UNIQUE VERSION
    FROM wmsys.wm$modified_tables
    WHERE table_name = 'SIG.SIG_QUA_IMG'
    AND workspace = 'NpCyPCX3dkOAHSuBMjGioQ=='
    AND VERSION > 4574
    AND VERSION <= 4575) j3
    WHERE t1.VERSION = j1.VERSION
    AND t1.ima_id = t2.ima_id
    AND t1.qim_inf_esq_x_tile = t2.qim_inf_esq_x_tile
    AND t1.qim_inf_esq_y_tile = t2.qim_inf_esq_y_tile
    AND t2.nextver != '-1'
    AND t2.nextver = j2.next_vers
    AND j2.VERSION = j3.VERSION))

    Hello Vitor,
    There are currently no known issues with version enabled tables that are partitioned. The merge operation may need to access all of the partitions of a table depending on the data that needs to be moved/copied from the child to the parent. This is the reason for the 'Partition Range All' step in the plan that you provided. The majority of the remaining steps are due to the hints that have been added, since this plan has provided the best performance for us in the past for this particular statement. If this is not the case for you, and you feel that another plan would yield better performance, then please let me know and I will take a look at it.
    One suggestion would be to make sure that the table was been recently analyzed so that the optimizer has the most current data about the table.
    Performance issues are very hard to fix without a reproducible test case, so it may be advisable to file a TAR if you continue to have significant performance issues with the mergeWorkspace operation.
    Thank You,
    Ben

Maybe you are looking for

  • Setting currency and measurement unit for a field in an ALV report

    Plz give sample code to set currency and measurement unit for a field in an ALV report

  • My experience of recent upgrade to BT Infinity

    First it did not go well. After a few days my broadband connection kept dropping out, often a much as ten times a day. Finally in despartartion I phoned the help desk and as usual I spoke to a nice gentleman 5,000 mile away with an accent I could not

  • HP Officejet Pro 8000 Wireless, Mac OS 10.7.2 can't get it set up to run wireless

    I have an iMac, OS 10.7.2, Airport Extreme router, and an HP Officejet Pro 8000 Wireless.  I recently replaced my router with an Airport Extreme.  My printer setup CD is for OS 10.4 or 10.5.  I'm trying to setup the 8000 wirelessly but without much l

  • Transport Error when Importing TR to QA system

    Hi All, We are receiving the below error when transporting a TR to Quality system. Detail Error message:   Execution of programs after import (XPRA)   Transport request   : XXXXXX   System              : XXX   tp path             : tp   Version and r

  • Windows Authentication and Zenworks Problem

    I have Zenworks 6.5.1.0 on my desktop. I make my computer part of our win2k3 domain. When I try to connect to sql server through the client tools using windows authentication the domain name doesn't show up correctly. It will show up as the computer_