22 April 2010

Showplan Operator of the Week – Concatenation

Fabiano continues in his mission to describe, one week at a time, all the major Showplan Operators used by SQL Server's Query Optimiser to build the Query Plan. This week he gets the Concatenation operator .

1010-Contatenation001.gif Concatenation

Showplan Operators are used by SQL Server’s Query Optimizer (QO)  to perform a particular operation within a query plan. A query plan will usually contain several of these physical operators. Each physical operation is represented in the Query Plan by an operator, and each operator is shown in the graphical execution plan by an icon. This week we’ll be featuring the concatenation showplan operator. Its behavior is quite simple; it receives one or more input streams and returns all the rows from each input stream in turn. We can see its effect whenever we use the Transact-SQL UNION ALL command.

Concatenation is a classic operator that can receive more than one input. It is both a logical and a physical operator.

Before we start to talk about concatenation, we need to understand some important points about showplan operators and execution plans.

All operators used in execution plans, implement three methods called Init(), GetNext() and Close(). Some operators can receive more than one input, so, these inputs will be processed at the Init() method. The concatenation is one example of these operators.

At the Init() method, the concatenation will initialize itself and set up any required data structures. After that, it will run the GetNext() method to read the first or the subsequent row of the input data, it runs this method until it has read all rows from the input data.

Let’s take the following query as a sample:

The following script will create a table TabTeste and populate with some garbage data.

The script above will populate 10000 rows at the TabTeste table. Now let’s run one query sample to look at the execution plan.

Graphical execution plan:


Text execution plan:

As we can see, this query is using one operator called Merge to join the tables, in the plan, the Merge operator is receiving two inputs (the table TabTeste twice).

The operator of the week, Concatenation, is a good example of an operator that receives more than one input. If, for example, we run the following query, we will see that it receives fours inputs.

Graphical execution plan:


Text execution plan:

The  concatenation operator receives the result of all “clustered index scan“  and copies all the rows to one output calling the methods Init() and GetNext(). These methods are called to each Input.

The Query Processor will execute this plan in the order that the operators appear in the plan, the first is the top one and the last is  the end one.

That’s all folks, I see you next week with more “Showplan Operators”.

If you missed last week’s thrilling Showplan Operator, The Assert, you can see it here

Keep up to date with Simple-Talk

For more articles like this delivered fortnightly, sign up to the Simple-Talk newsletter

This post has been viewed 12984 times – thanks for reading.

  • Rate
    [Total: 21    Average: 4/5]
  • Share

Fabiano Amorim

View all articles by Fabiano Amorim

Related articles

Also in BI

Relational Algebra and its implications for NoSQL databases

With the rise of NoSQL databases that are exploiting aspects of SQL for querying, and are embracing full transactionality, is there a danger of the data-document model's hierarchical nature causing a fundamental conflict with relational theory? We asked our relational expert, Hugh Bin-Haad to expound a difficult area for database theorists.… Read more

Also in Learn SQL Server

SQL Server System Views: The Basics

When maintaining or refactoring an unfamiliar database, you'll need a fast way to uncover all sorts of facts about the database, its tables, columns keys and indexes. SQL Server's plethora of system catalog views, INFORMATION_SCHEMA views, and dynamic management views contain all the metadata you need, but it isn't always obvious which views are best to use for which sort of information. Many of us could do with a simple explanation, and who better to provide one than Rob Sheldon?… Read more

Also in Optimiser


When your SQL Server database is set to have its statistics automatically updated, you will probably conclude that, whenever the distribution statistics are out-of-date, they will be updated before the next query is executed against that index or table. Curiously, this isn't always the case. What actually happens is that the statistics only gets updated if needed by the query optimiser to determine an effective query plan.… Read more

Also in Showplan

Complete Showplan Operators

Fabiano Amorim has taken the time to reallv drill into the behavior of a small set of execution plan operators in an effort to explain the optimizer's behavior. He's explored why things happen, how you can change them, positively or negatively, and he's done it all in an approachable style.… Read more

Join Simple Talk

Join over 200,000 Microsoft professionals, and get full, free access to technical articles, our twice-monthly Simple Talk newsletter, and free SQL tools.

Sign up

See what's happening behind the scenes

Take a peek at the bowels of the ship – the lower decks – the actual servers of SQL Server Central itself.

See what's happening