Sequence Project Operator

Hi Geeks,

Sequence project operator adds columns in order to perform computations over an ordered set and divides the input set into segments based on the value of one or more columns. This is both a physical and logical operator.

Consider following query that assigns consecutive rank to each row of a partition in other words group of records that are partitioned by the Color column and ordered by ProductNumber column. If more than one column happen to have same value for ProductNumber column, they get the same rank.

USE [AdventureWorks2012]

SELECT DENSE_RANK() OVER (
	PARTITION BY Product.Color
	ORDER BY Product.ProductNumber) AS [Rank],
Product.Name, Product.Color,Product.ProductNumber,Product.SafetyStockLevel,Product.ModifiedDate
FROM Production.Product

SeqProjGrphPlan

Two Segments (you can read more on segment operator here) and Sequence Project work together to produce result of the DENSE_RANK OVER PARTITON BY clause used in the query statement. The first Segment operator has a GROUP BY argument of Color column and it uses segment column labelled with [Segment1004] to specify if the current row is first row that belongs to a new group.

Segment1_ToolTip

   

The second Segment operator is required because then DENSE_RANK() changes when the current value differs from previous row. In order to house this, the query plan requires a second flag and stored in the second segment column [Segment1005].

Segment2_ToolTip

With these two segments, now Sequence Project can decide if it has to increment, rest or leave the internal value for the DENSE_RANK() function. Sequence project adds this internal value as a new column and same is reflecting in our example as [Expr1003].

SeqProj_TT

That’s all for today, I’ll be back tomorrow with a new operator, till then.

Happy Learning!

Regards,

Kanchan

Like us on FaceBook | Join the fastest growing SQL Server group on FaceBook | Follow me on Twitter | Follow me on FaceBook

   

About Kanchan Bhattacharyya

Kanchan is an astute IT professional, a seasoned SQL Database Administrator with 13+ years of industry experience. A calculated risk taker with deep technical knowledge and has gained proficiency in database consulting and solutions across different environments. Kanchan holds MBA degree in IT and an International Executive MBA in Project Management. He is very passionate about SQL Server and holds MCSE (Data Platform), MCSA – SQL 2012, MCITP – SQL 2008 certifications. Currently he is focusing on cloud and latest releases of SQL Server. When not working, Kanchan likes to spend his time reading on new technical developments specifically on SQL Server and other related technologies.

View all posts by Kanchan Bhattacharyya →

Leave a Reply

Your email address will not be published.