How to Find Table Cardinality from the Execution Plan? – Interview Question of the Week #213

Question: How do you find table cardinality in an execution plan? Inspect the scan or seek operator’s TableCardinality property, or locate that attribute in the plan XML. It is the table cardinality used by that compiled plan, not a fresh exact count of returned rows.

A small scoop holds a sample in front of a broad full tray

I get this question during performance health checks. The original example uses AdventureWorks2014 and returns only the first 1,000 rows:

SELECT TOP (1000) *
FROM AdventureWorks2014.Person.Address;

Enable the actual execution plan with Ctrl+M, then execute the query. Selecting the table-access operator and pressing F4 opens its Properties window. Find TableCardinality there; it isn’t necessarily the rightmost operator in every plan.

Historical AdventureWorks2014 scan: TableCardinality is 19614 while only 1000 rows are read

The original screenshot is useful: TableCardinality is 19,614, while the TOP request reads 1,000 rows. Those values answer different questions. The table value is information used during optimization and can differ from the table’s current row count if the plan or its statistics are stale.

Find the same value in XML

Right-click the plan and choose Show Execution Plan XML. Search for TableCardinality. In the original plan the attribute is:

TableCardinality="19614"

This is an XML attribute excerpt, not a standalone XML document or a SQL statement. It is the same compiled-plan property shown by SSMS, not an independent count.

If you need the exact current count instead, run COUNT_BIG(*) against the table, with the appropriate isolation level for your requirement. The editable example uses AdventureWorks2025 on the current lab; the retained screenshot remains explicitly historical.

These are still the two convenient ways I use to inspect the plan’s table cardinality. If you have another useful method, share it in the comments and I will credit you.

Related: cardinality of an executed query and viewing execution plans in SSMS. Microsoft: cardinality estimation

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.

Execution Plan, SQL Scripts, SQL Server, SQL Server Management Studio, SQL Statistics
Previous Post
What is Consolidation of Index? – Interview Question of the Week #212
Next Post
How to Extract Alphanumeric Only From A String? – Interview Question of the Week #214

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.