Amazon Redshift
Database Developer Guide (API Version 2012-12-01)

Analyzing the Query Plan

Before analyzing the query plan, you should be familiar with how to read it. If you are unfamiliar with reading a query plan, we recommend that you read Query Plan before proceeding.

Run the EXPLAIN command to get a query plan. To analyze the data provided by the query plan, follow these steps:

  1. Identify the steps with the highest cost. Concentrate on optimizing those when proceeding through the remaining steps.

  2. Look at the join types:

    • Nested Loop: Such joins usually occur because a join condition was omitted. For recommended solutions, see Nested Loop.

    • Hash and Hash Join: Hash joins are used when joining tables where the join columns are not distribution keys and also not sort keys. For recommended solutions, see Hash Join.

    • Merge Join: No change is needed.

  3. Notice which table is used for the inner join, and which for the outer join. The query engine generally chooses the smaller table for the inner join, and the larger table for the outer join. If such a choice doesn't occur, your statistics are likely out of date. For recommended solutions, see Table Statistics Missing or Out of Date.

  4. See if there are any high-cost sort operations. If there are, see Unsorted or Missorted Rows for recommended solutions.

  5. Look for the following broadcast operators where there are high-cost operations:

    • DS_BCAST_INNER: Indicates the table is broadcast to all the compute nodes, which is fine for a small table but not ideal for a larger table.

    • DS_DIST_ALL_INNER: Indicates that all of the workload is on a single slice.

    • DS_DIST_BOTH: Indicates heavy redistribution.

    For recommended solutions for these situations, see Suboptimal Data Distribution.