Query plan

Since SQL is declarative, there are typically many alternative ways to execute a given query, with widely varying performance.

A given database management system may offer one or more mechanisms for returning the plan for a given query.

Other tools allow a special mode to be set on the connection to cause the DBMS to return a textual description of the query plan.

The textual plan given for the same query in the screenshot is shown here: It indicates that the query engine will do a scan over the primary key index on the Employee table and a matching seek through the primary key index (the ContactID column) on the Contact table to find matching rows.

It can also show that the database is not properly taking advantage of existing indexes (see query optimizer).

Microsoft SQL Server Management Studio displaying a sample query plan.