5.2. Cost in EXPLAIN

During planning, the cost associated with each node of the plan is computedbased on the table statistics for the tables in the query. This calculatedcost is printed as part of the output of an EXPLAIN statement.

Cost information is displayed in the plan tree using the format {rows: XX (XX), cpu: XX, memory: XX, network: XX}. rows refers to the expectednumber of rows output by each plan node during execution. The value in theparentheses following the number of rows refers to the expected size of the dataoutput by each plan node in bytes. Other parameters indicate the estimatedamount of CPU, memory, and network utilized by the execution of a plan node.These values do not represent any actual unit, but are numbers that are used tocompare the relative costs between plan nodes, allowing the optimizer to choosethe best plan for executing a query. If any of the values is not known, a ?is printed.

For example:

  1. presto:default> EXPLAIN SELECT comment FROM tpch.sf1.nation WHERE nationkey > 3;
  2.  
  3. - Output[comment] => [[comment]]
  4. Estimates: {rows: 22 (1.69kB), cpu: 6148.25, memory: 0.00, network: 1734.25}
  5. - RemoteExchange[GATHER] => [[comment]]
  6. Estimates: {rows: 22 (1.69kB), cpu: 6148.25, memory: 0.00, network: 1734.25}
  7. - ScanFilterProject[table = tpch:nation:sf1.0, filterPredicate = ("nationkey" > BIGINT '3')] => [[comment]]
  8. Estimates: {rows: 25 (1.94kB), cpu: 2207.00, memory: 0.00, network: 0.00}/{rows: 22 (1.69kB), cpu: 4414.00, memory: 0.00, network: 0.00}/{rows: 22 (1.69kB), cpu: 6148.25, memory: 0.00, network: 0.00}
  9. nationkey := tpch:nationkey
  10. comment := tpch:comment

Generally, there is only one cost printed for each plan node. However, when aScan operator is combined with a Filter and/or Project operator,then multiple cost structures will be printed, each corresponding to anindividual logical part of the combined operator. For example, three coststructures will be printed for a ScanFilterProject operator, correspondingto the Scan, Filter, and Project parts of the operator, in that order.

Estimated cost is also printed in EXPLAIN ANALYZE in addition to actualruntime statistics.