2. WHAT IS IT?
• Partitioning makes large table or indexes more
manageable.
• It enables you to manage and access subsets
of data quickly and efficiently.
• By using partitioning, an operation such as
insert, update or delete takes only seconds
instead of minutes or hours.
• However this requires us to make use of good
partitioning practices in our queries .
3. MAIN BENEFITS OF PARTITIONING
• Transfer or access subsets of data quickly and efficiently,
while maintaining the integrity of a data collection.
• Perform maintenance operations on one or more partitions
more quickly. The operations are more efficient because
they target only these data subsets, instead of the whole
table.
• Improve query performance based on the types of queries
and the joins used. For example, the query optimizer can
process equi-join queries between two or more partitioned
tables faster when the partitioning columns in the tables
are the same, because the partitions themselves can be
joined.
4. MAIN CONCEPTS AND COMPONENTS
• Partition function – defines the number of partitions that
the table will have and how the boundaries of the partitions are
defined. Ex: our big tables are partitioned in daily partitions based
on the calendarDateCET column.
• Partition scheme - a database object that maps the
partitions of a partition function to a set of filegroups. The reason
for placing your partitions on separate filegroups is to make sure
that you can independently performs backup operations on
partitions.
• Partitioning column – the column of a table or index that a
partition functions uses to partition the table or index.
• Partition elimination – the process by which the query
optimizer accesses only the relevant partitions to satisfy the filter
criteria of the query.
5. PARTITION INFORMATION (1)
SELECT *
FROM TDW.sys.partition_range_values prv
INNER JOIN TDW.sys.partition_functions pf ON prv.function_id = pf.function_id
WHERE pf.name = 'partitionDayFunction‘
7. PARTITION ELIMINATION
[ database_name. ] $PARTITION.partition_function_name(expression)
tdw.$partition.partitionDayFunction(calendarDateCET)
Ex: SELECT DISTINCT calendarDateCET
FROM tdw..tgameRound
WHERE tdw.$partition.partitionDayFunction(calendarDateCET) = 130
8. USING PARTITION ELIMINATION (1)
• The below function will eliminate partitions
directly when doing the join between the
tables and therefore it will only join with those
records in the selected partitions.
FROM tdw.dbo.tcustomer c
JOIN tdw.dbo.tinternalCustomer ic ON c.sk_customer = ic.sk_customer
LEFT JOIN tdw.dbo.tinternalTransaction it
ON ic.sk_internalCustomer = it.sk_internalCustomer
AND tdw.$partition.partitionDayFunction(calendarDateCET) >= @curr_partition
9. USING PARTITION ELIMINATION (2)
• If we have a look at the example below, we are able to merge into
the tgameRound table by specifying which partitions we will be
merging into. This allows us to avoid having to switch out partitions
into a new table in order to be able to do the merge. The
#all_partitions table will hold the partition numbers in which we
will be merging data.
MERGE INTO tdw.dbo.tgameRound dst
USING #calculatedGameRounds src
ON (src.externalGameRoundId = dst.externalGameRoundId AND
src.sk_brand = dst.sk_brand AND
src.sk_provider = dst.sk_provider AND
src.sk_internalCustomer = dst.sk_internalCustomer AND
src.sk_wltExternalGame = dst.sk_wltExternalGame AND
tdw.$partition.partitionDayFunction(calendarDateCET) IN
(SELECT partitionNumbers FROM #all_partitions))